Possible Duplicate:
How to print message from caught exception?
Apologies if this is basic or duplicated – I did several searches first but didn’t find anything that answered this.
If I do something basic like:
throw exception("This thing didn't work");
Where can I see that? The string doesn’t show up in the output console, stack trace, or any of the .log files associated with the project. Makes me wonder why I’m even putting a string there if it can’t be seen anywhere. I can of course use the stack trace to see where it blew up, but that kind of defeats the purpose of having exceptions in the first place.
In Java, when I give it a string, I’ll see that string in the output somewhere. I just wonder if it’s possible to reproduce this behavior in C++.
You must catch the exception in order to see the string.
It can be useful to have an exception handler of last resort as follows:
In a GUI application you can have a catch statement in the main event loop, and display the error message in a message box.
In an event-driven non-GUI application you can also have a catch statement in the main event loop, and write the error message to a log file.
These methods will make sure that you see all exceptions. Of course, most exceptions should be caught before they reach your exception handler of last resort.