Re: Structured Exception Handling (was: Try Finally...)

From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 11/03/04


Date: Wed, 3 Nov 2004 13:43:48 +0100


"VBDis" <vbdis@aol.com> wrote in message
news:20041031203233.24462.00000778@mb-m23.aol.com...
> Im Artikel <4184d94b$0$37789$e4fe514c@news.xs4all.nl>, "Maarten Wiltink"
> <maarten@kittensandcats.net> schreibt:

>> Windows SEH provides building blocks: guard frames, and hooks to
>> exception handlers and termination handlers. Where a compiler puts
>> exception filtering, except clauses, and finally clauses, is up to
>> the compiler.
>
> You should understand that no phyiscal difference exists between
> exception filters, exception handlers, and termination handlers. An
> exception handler /is/ a piece of code that /behaves as/ an exception
> handler. ...

I have been careful to distinguish between except clauses and exception
handlers, and between finally clauses and, er, exception handlers, too
(latest insight being that both types of clauses are executed during the
second phase of Windows SEH). The filtering I'm not concerned with; it
really has very little bearing on the relative timing of Object Pascal's
except and finally clauses.

I realise that in the end, all machine code is created equal, and the
difference is only in how it's placed where Windows SEH code will call
into it.

[...]
> With regards to exception filters and handlers, the invocation
> sequence is as follows:
> 1) an exception filter signals to stop arbitration, indicating
> where to resume normal program operation.
> 2) the termination handlers up to the resume point run.
> 3) operation resumes as determined before, typically in the
> exception handler related to the stopping exception filter.
>
> Consequently an exception filter is a handler that signals to stop
> the search for an exception handler. An exception handler can be
> everything that becomes active when normal program operation resumes.

"Exception handler" is the Windows SEH term for the code that runs
during the first guard chain traversal. You seem to be using it with
a different meaning. Anyhow I can't make sense of your point 3.

I think both (OP) finally clauses and except clauses end up in (WinSEH)
termination handlers. Finally clauses always run and except clauses run
when their filter is fulfilled but they reraise the exception. The
final except clause does not reraise the exception. After that, execution
might resume at the excepting machine code instruction, or _after_ the
exception handler whose filter signalled a stop.

Groetjes,
Maarten Wiltink



Relevant Pages

  • Re: Question for Randy or Frank
    ... This is an HLA standard library facility. ... >> that you won't get under Windows. ... Then there's the "exception handling" approach to errors (which the HLA ... rather than solely "one big exception handler" wrapping the entire program ...
    (alt.lang.asm)
  • [NT] PNG (Portable Network Graphics) Deflate Heap Corruption Vulnerability (Windows)
    ... Beyond Security would like to welcome Tiscali World Online ... exception filter, overwriting the pointer to the handler with the address ... is set to the address of the unhandled exception filter hook. ...
    (Securiteam)
  • StackWalk behaviour
    ... I am adding an exception handler to certain of our build configurations ... actually dump the callstack for each thread. ... the second and third seemed to result in a valid callstack. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Practical error/exception handling...
    ... > try-except blocks until they reach the exception handler that really ... > If you have a catch-all exception handler, ... > the stack to the next exception handler. ... Raptor squirms in seat, ...
    (alt.comp.lang.borland-delphi)
  • Re: Try Finally...
    ... >> exception handler procedure was set in sysutils.pas. ... > none of which are provided by the current Delphi exception handlers. ... so you have no problem writing your own exception handler. ... exception handling right. ...
    (comp.lang.pascal.delphi.misc)