Reputation: 521
Out of my curiosity..
I notice when I throw exceptions from constructor, if I compiled the code in debug mode and if I click on continue debugging (or continue stepping through), it won't exit the constructor until it reaches the end. Please note I don't have try{}catch{} wrapping the code that instantiate MyClass object.
I tried this in release mode, and can't really tell if it exits the constructor after the first throw or the last throw. Do you know if in release mode it leaves ctor since the first throw or the last? And why does it let me go to the next line when I'm in debug? shouldn't throw just exit the scope it's in?
MyClass::MyClass()
{
throw "exception1";
throw "exception2";
throw "exception3";
}
MyClass a;
Upvotes: 1
Views: 256
Reputation: 9039
I suspect that it's a debugging issue. An uncaught exception should, by default, kill the program. But your debugger stops the program at the line that caused the exception, instead. And the "continue debugging" button tells the debugger to just ignore the last fatal problem and continue going.
So the debugger continues on in the program until it reaches the second throw
. Which would, again, be fatal. So the debugger stops there. Etc.
If there's a place that actually catches the thrown exception, you should see different behavior.
Upvotes: 4