Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will an exception get passed back to the calling method?

Let's say in one method I have

try {
callme();
}
catch
{
// handle callme exception
}

Now let's say callme() calls method1() which in turn calls method2() -- If method2() throws an exception should it get thrown back to method1()'s frame, which will then stop any further execution inside of itself and pass the exception thrown from method2() to callme()'s frame and back to the original stackframe?

Will the same occur if I am stepping through code? Or will VS2008 stop as soon as it sees an exception if it is not handled in the originating method?

I am throwing an Exception but then the debugger complains of:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

as soon as i hit the closing bracket of method2().

I'm a bit confused, I thought exceptions were supposed to be passed back all the way up.

like image 638
Matt Avatar asked Dec 23 '22 09:12

Matt


1 Answers

At runtime, the exception will bubble up the call stack until one of the following happens:

  • It is caught in a Catch block
  • It is caught by a global exception handler
  • It is not caught by user code and a general exception message is displayed

When debugging the situation is a bit different because the debugger can be set to break on unhandled user exceptions. This could be what's happening in your case. Check the Visual Studio option Debug / Exceptions to see if your debugger is set to catch any unhandled exception before it bubbles up and out of user code.

like image 200
Eric J. Avatar answered Jan 06 '23 10:01

Eric J.