Re: Exception Handling...

nobody_at_noplace.not
Date: 06/26/04


Date: Sat, 26 Jun 2004 14:33:57 -0400

On 26 Jun 2004 14:11:25 GMT, vbdis@aol.com (VBDis) wrote:

>Im Artikel <69MCc.63427$sj4.34027@news-server.bigpond.net.au>, "David Reeve"
><dree4456@big-pond.net.au> schreibt:
>
>>The OS then unwinds the stack frame of the
>>thread which executed the errant code, procedure call by procedure call as
>>it looks for what??........
>
>Isn't the FS segment register used for exception handling? I vaguely remember
>its use in Microsoft compilers...

I found an article on this, it's a bit old, but it does clarify a lot.

As I now understand it... FS points to the beginning of a Stack Frame
belonging to the current block of code being executed.

At FS:[0] the executing code can register an exception handler by providing
it's entry address and at FS:[4] it must list the address of the previous
exception handler, creating a linked list of "exception registrations"
  
When an exception occurs Windows jumps into an exception handling routine
that assumes the last handler in the chain is the current handler and does
a controlled jump to the address at FS:[0]

The jump is to a callback, an external entry point where the exception is
dealt with and the return value from the callback tells windows how to
proceed... whether the error is handled or not.

If the error is handled, an "unwind" is initiated in which a second visit to
each callback is made, allowing for whatever post-error cleanup is required.

When a block of code exits, the stack frame is dismantled resulting in the
exception handler's address being removed from the end of the list, leaving
the registration of all previous handlers in place. Thus Windows always has
the most current handler available to it.

I'm not 100% certain yet but it strikes me this pretty much corresponds to
Try/Except/Finally/ as in...

        Try // register exception callback @Except block
                
                DoThisCode;

        Except // callback: handle exception and signal windows it's done

                FixThisProblem;

        Finally // unwinding: clean up after ourselves (i.e. do anyway)

                CleanupAfterThisProblem;

        end; // exception registration is destroyed with stack frame.

Of course this isn't exactly how DP works... But I'm guessing that's what
the OS gurus hand in mind.

-----
Laura



Relevant Pages

  • Re: Try Finally...
    ... exception occurs, the exception mechanism climbs up through all these ... blocks, executing finally blocks, and unwinding the stack until the ... will be handeld by the main exception handler. ... of a profound truth may well be another profound truth." ...
    (comp.lang.pascal.delphi.misc)
  • Re: QC#6682 - is there a fix?
    ... register a handler for TApplication.OnException before creating your ... Then your handler will get notified about the exception and the ... quality low level Delphi components ...
    (borland.public.delphi.language.objectpascal)
  • Re: Try Finally...
    ... Now we can protect every more or less specialized action ... an error indication (exception or error code) has to be ... an according exception handler can be inserted into the code. ... resources, as they are related to specific actions. ...
    (comp.lang.pascal.delphi.misc)
  • Re: WinForms bug? ThreadException not invoked on Exceptions in system code pre-processing the me
    ... Message Queue and invoking the appropriate handler. ... if an Exception is raised during the PRE-PROCESSING of a Windows ... And because any handling will probably fail if there is no memory, the CLR will terminate the application without attempting to call the ApplicationException or UnhandledException events. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: BackgroungWork taske ended for no appearent reason
    ... To do the same thing with Try/Catch blocks requires wrapping every file access with a Do While ... ... If there was any exception thrown in your DoWork event handler, ... If the operation raises an exception that your code does not handle, ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vb)