Re: stack questions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"DC" <***@***.com> wrote in message
news:e8Ym2Wc9GHA.4084@xxxxxxxxxxxxxxxxxxxxxxx
| Hi all,
|
| First of all, let me asure you you will not be doing my homework for me if
| you are good enough to reply - I have been a professional programmer for a
| couple of years now, I just never studied Computer Science so I like to
try
| and 'catch up' on stuff like this at the weekend.
|
| Having said that I have a couple of questions around the excution stack,
in
| particular 2 things are bothing me:
|
| 1. It is said that on encountering an exception, the execution engine
| "unwinds" the call stack looking for a suitable exception handler. In the
| example below can we assume that the address of the error handling code is
| pushed onto the stack as the return address before executing the try block
| and that, infact, the code within the try block is in itself executed as a
| function call within it's own stack frame? This can't be the answer though
| as the catch block only executes where the stack is unwinding 'in error'
not
| simply in unwinding during normal flow. So what is really going on??
|
| try
| {
| //some work
| }
| catch
| {
| //handling code
| }
|
A two phase exception handling model is employed by the CLR, and CLR
exceptions are implemented on top of the Windows SEH mechanism (as are the
C++ exceptions).
When an exception is thrown, the CLR initiates the first phase which consist
of a stack walk to search for an appropriate exception handler (the one
who's filter is able to deal with the exception!), in the second phase the
stack is unwound until the frame containing the handler is reached. Note
that unwinding the stack, causes the finally blocks on the unwounded frames
to be executed.
More gory detail, can be found here:
http://blogs.msdn.com/cbrumme/archive/2003/10/01/51524.aspx



Willy.


.



Relevant Pages

  • Re: N1298 - try/finally for C
    ... try-less function blocks, to be caught at the next highest ... I don't know why stack unwinding keeps coming into the discussion. ... have to check to see if the caught exception is the ...
    (comp.std.c)
  • Re: VM as target, was Is Assembler Language essential
    ... stack unwinding in some approaches to exception handling (IP-range based ... general (universally keeping the frame pointer allows very lightweight ... proper unwinding, and where the information necessary for this unwinding is ...
    (comp.compilers)
  • Re: stack questions
    ... It is said that on encountering an exception, the execution engine ... "unwinds" the call stack looking for a suitable exception handler. ... simply in unwinding during normal flow. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: stack questions
    ... try block and to implement throw by restoring the registers. ... Having said that I have a couple of questions around the excution stack, ... It is said that on encountering an exception, the execution engine ... not simply in unwinding during normal flow. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Try Finally...
    ... finally continues at the point where the exception is handled. ... the Windows mechanism takes a two-stage ... with the first stage only following the stack and the second ... execution finally continues after the handler that handles the exception. ...
    (comp.lang.pascal.delphi.misc)