Re: Try Finally...

From: L D Blake (not_at_any.adr)
Date: 10/26/04


Date: Mon, 25 Oct 2004 20:02:41 -0400

On Mon, 25 Oct 2004 18:14:58 GMT, "Martin Harvey (Demon account)"
<martin@nospam_pergolesi.demon.co.uk> wrote:

>I'm amazed you folks are even having this argument. It's real simple.
>The only real difficuly that is going on is understanding the
>different viewpoint between language constructs and S.E.H. constructs.

By way of analogy we have two things going on here...

The engine and the car around the engine. While they work together, they are
not the same thing.

SEH (Structured Exception Handling) is a stack based mechanism **administered
by windows** for catching and dealing with code errors.

Try/Except and Try/Finally are the car around the SEH engine. This is a
language level thing, implemented in the core system units of whatever
language... in System.pas and Sysutils.pas in our case.

As you point out Martin... it is a mistake to think they are one and the same
thing... SEH does code checking and error catching, then creates a call to
the exception handler registered in the stack. It does this entirely without
the knowledge or consent of the application or language code. Should an
exception occur with no SEH frames on the stack, the system terminates at the
unhandled exception handler. For the language's part, it's responsible for
registering and removing SEH frames from the stack... the language (and to a
lesser degree, user code) decides, on a case by case basis which exceptions
are handled an which are not.

So Try/Except and Try/Finally are the conveyance around the SEH engine.

>Now ... as concerns continuing versus not continuing.... there are
>several points where confusion may be present, and I'll attempt to
>clear this up.
>
>- Skipping the subtleties, if I remember rightly, there are basically
>three things that an S.E.H registered handler can do
>
>- continuing the program because the exception has been handled.
>- continuing the search for an appropriate handler.
>- stopping the whole shebang at that point, and terminating the app.

Actually there's four...

-- Handle the Exception and carry on
-- Don't handle the exception and continue searching for a handler
-- Unwind exceptions (remove SEH frames).

The actual SEH handlers don't decide whether to terminate the program or
not... the program is going to terminate when an exception occurs and no
handler can be found to deal with it.

>If LDB wants to implement a custom mechanism, the thing one should be
>doing with finally blocks is NOT terminating the program, but
>continuing the search. HOWEVER, this may well require some custom code
>to unwind the stack.

Actually, no... I've been experimenting with this. If I pass on the exception
(don't handle, continue search) if there's a try/except block around the
finally block, the exception does get handled and the program can continue
along... otherwise it falls along to the unhandled exception handler and
terminates. Alternatively I can have it stop the application every time by
absorbing the exception and passing it directly to the unhandled handler.

>Oh, and BTW, I'd recommend people who don't know how S.E.H works
>internally at least do a google search and a bit of reading - it's
>quite interesting.

Yeah... 'cause it sure ain't what most people here seem to think it is.

-----
Laura



Relevant Pages

  • Re: initial lang spec: SXIL...
    ... Shouldn't some of that functionality be moved into the exception ... but, of course, natively using SEH requires compiler support. ... throws a fixed exception code in my case, and generic handlers are used. ... It took many years, and a language review, before I realized that my fond ...
    (comp.lang.misc)
  • Re: Implementing Exception Handling in a VM
    ... Given that the implementing language has SEH, can ... I leverage this fact to add exception support in my Pascal-like ... handling system in your VM. ...
    (comp.compilers)
  • Re: Try Finally...
    ... >>exception, the exception is not created in Delphi (or whatever language we are ... followed by the exception handler determined in the first pass. ... >exception handler executes only after all termination handlers have executed. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Try Finally...
    ... >> the stack, as long as the exception gets handled by the book. ... What I see is that your language uses the same syntax ... or perhaps one handler level out, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Exceptions, and try...finally
    ... If the exception stopped after ... The Delphi language does not behave the way you say it does. ... >> then that line will not execute. ... That's caused by the exception handler installed by the ...
    (comp.lang.pascal.delphi.misc)