Hi again,

Is it possible when throwing a custom exception to pause the program instead of just exiting?
I have a throw customexception("error msg") in my main and I want to print the error msg and then press return to exit or something like that.

Thanks

@obscured47 You can do anything once you catch the exception.
Why do you want to throw an exception to pause the execution? There could be better ways to do that.
Can you post small segemt of your code and let us know the behaviour you are expecting ?

Sure,

Say I have:

class custom_exception : public std::runtime_error
{
public:
       custom_exception(string msg) { cout << "Error: " << msg << endl; }
};

and then in my main:

if (x>10) throw custom_exception("number bigger than 10");

After this, the program must end (because it cannot continue with the given data)
I want to throw the exception, the user will see the msg, press return and then terminate.

By the way I know that the code above doesn't make a lot of sense but it's just to show what I mean. Hope its clear :)

You need to catch the exception. You need to write a catch block. If you let OS to handle your first chance exception it is going to simply terminate the process because OS does not know which way you want to terminate.
You can try writing the catch block and exit from there.

>I want to throw the exception, the user will see the msg, press return and then terminate.
Set your own custom termination handler. Look in your reference for the <exception> header to get more details.

thanks :) solved!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.