Re: Try Finally...

From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 10/26/04


Date: Tue, 26 Oct 2004 10:45:12 +0200


"L D Blake" <not@any.adr> wrote in message
news:ej8rn01903rqqfn8b7sbrt3lstntt0sko8@4ax.com...
[...]

> The first shortcoming, in fact the reason I joined this group, has
> already been explained in some depth... Try/Except handling shuts
> down if the SysUtils unit is not loaded. There is no error message,
> no syntax error, nothing... it just stops working. THAT can be a
> serious problem if you aren't expecting it... Reserved Words should
> not just shut down.

This, I agree with. It may have been a feeble attempt on Borland's
part to allow programmers to keep their applications slightly leaner.
But it's not a very good way, although it's easy, and the cost is out
of proportion to the benefits.

[...]
> See that's just it... Finally doesn't handle the actual exception and
> thus it *must not* unwind the stack.

I'm not sure about this. Exceptions "climb out" through the call chain,
executing finally and except clauses along the way, and execution
finally continues at the point where the exception is handled. That
suggests that unwinding the stack is the right thing to do along the
way.

If I've understood correctly, the Windows mechanism takes a two-stage
approach, with the first stage only following the stack and the second
one unwinding it. Why it's done this way, I don't understand. Delphi
appears to have collated these two stages into a single one, bypassing
Windows' code. I don't consider this bad in itself; it's just different.
The final effect is the same: all the right code gets executed, and
execution finally continues after the handler that handles the exception.

[...]

> Reading the code, one gets the impression that Borland's guys really
> didn't understand how SEH works... Hell knows I had a rough enough
> time wrapping my head around it and it's not very well documented to
> begin with. They've invested a LOT of code in what looks for all the
> world to be an attempt to create the entire concept within Delphi
> rather than using the windows provided mechanism. (Same thing they
> did with their memory manager)

More likely Borland's guys wanted something Windows couldn't offer them:
exception _objects_. So they built their own stack unwinding, using the
data structures that Windows keeps, and adding their own behaviour on
the side.

That you don't care for this feature doesn't mean it's irrelevant to
other people. Having exceptions be objects does have its benefits, even
if you don't use it every day, or even if you specifically don't use it
at all.

Groetjes,
Maarten Wiltink



Relevant Pages

  • 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: Access violation bug in XP but not 2K
    ... In the stack below, your `esi` register contains feeefeee, that is a fill ... and try to repro under debugger. ... I've tried using WinDbg.exe "Microsoft Debugging Tools for Windows" to ... First chance exceptions are reported before any exception handling. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Program execution in AS400
    ... A newbie from Mainframe into the world of AS400. ... faces a unmonitored exception. ... the execution of program is ended in ... the system has a very robust and well structured call stack. ...
    (comp.sys.ibm.as400.misc)
  • Re: Program execution in AS400
    ... faces a unmonitored exception. ... the execution of program is ended in ... the system has a very robust and well structured call stack. ... what to do when the *escape message is unmonitored for. ...
    (comp.sys.ibm.as400.misc)
  • Re: try, catch, finally- whats the point of finally?
    ... > The exception will bubble up the call stack and get caught by ... > execution would stop at the exception and be thrown up the stack ...
    (microsoft.public.dotnet.languages.csharp)