Order of processing of call processing frame stacks in the call stack

What is the order in which exception handling stack frames are pushed onto the call stack in C #. If I have a method:

private void MyMethod() {
  try {
    DoSomething();  
  }
  catch (Exception ex)
  {
    //Handle
  }
}

      

Is there a separate stacking stack for each exception handler as follows?

DoSomething stackframe<br/>
Exception stackframe<br/>
MyMethod stackframe<br/>

      

OR

DoSomething stackframe<br />
MyMethod stackframe<br />
Exception stackframe<br />

      

OR

something else?

+2


source to share


1 answer


No, adding an exception handler does not add a new frame to the call stack. It simply adds the appropriate information so that when an exception is thrown, at each level of the call stack, the structure can find an appropriate handler for that exception (if there really is a handler).



It's a bit like garbage collection, where at any point in the execution the GC can decide which local variables should still be considered GC roots - essentially it's more for the method than the executable itself :)

+1


source







All Articles