Re: Exception Handling...

From: Rob Kennedy (me3_at_privacy.net)
Date: 06/29/04


Date: Tue, 29 Jun 2004 10:58:03 -0500

Maarten Wiltink wrote:
> I had actually expected the two cases to look more like each other.
> It occurred to me a couple of days ago that try-except and try-finally
> need not be implemented very differently. Both need to jump to a
> section of code that executes, perhaps checking if it should, then
> either cleans up the exception status or doesn't, and continues.

They're really more similar than the code lets on. The try-except code
generates a jump to HandleAnyException or HandleOnException. The
try-finally code generates a jump to HandleFinally. Those three routines
all do very similar things.

The major difference (at least in the compiler-generated code) is in
where the "try" statement tells the OS to jump to in the event of an
exception. Try-except jumps to the top of the "except" block;
try-finally jumps to the bottom of the "finally" block (both
destinations correspond to the location of the jump to HandleXXXX). The
"up-side down" try-finally handling, presumably, is to allow normal,
non-exception, execution to proceed as smoothly as possible.

The problem, for someone looking to rewrite Delphi's exception-handling
routines, is not so much in understanding the compiler-generated code
but in understanding what's going on inside System.pas and SysUtils.pas.
Two things making it difficult to read are that it's in assembler and
that there are several places that use JMP to go to another subroutine
instead of using CALL -- it's like following goto-laden code.

> Perhaps it's a little too idealistic for real compiler writers. I know
> that it always bugged me that only one of two different things may
> happen after a try statement.

Well, how many other things did you want?

-- 
Rob


Relevant Pages

  • Re: MetroidRL 0.7DRL Released
    ... the elevation of the initial jump must be being ... Start up a new game so that you are outside on the rocky ground. ... unmanaged exception relating to the Music manager being running on ... (unless the uncaught exception behaviour is overridden again). ...
    (rec.games.roguelike.development)
  • Re: Exception Handling...
    ... >HandleZeroDivide and some other stuff I don't understand being pushed on ... private data on top of the Exception Registration... ... But why would it go there if the registration on the stack points to your ... >the jump to HandleZeroDivide, followed by the normal exit code. ...
    (comp.lang.pascal.delphi.misc)
  • Re: possible to skip code from sub functions?
    ... Do this without an exception or a return value on any function: ... void B ... Jump j = new Jump; ... Or make it jump back to the scope level ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Triki, Ace, Eki and Paolo are gone from Disco
    ... or are the rats leaving the sinking ship? ... they pushed or did they jump? ... With the exception of Ekimov, ...
    (rec.bicycles.racing)
  • Re: MetroidRL 0.7DRL Released
    ... And then you can jump again from ... When you are floating in the air, you cannot move or else you will ... not the gradual descent that you get when falling from ... security exception and I think it was most likely caused by trying to ...
    (rec.games.roguelike.development)