Re: Implementing Exception Handling in a VM



Mark Andrews (The Other One) wrote:

Some time ago I wrote a simple Pascal-like language that ran on an
equally simple VM--all implemented in Delphi. I'd like to update the
language to use exception handling constructs such as try-except-end and
try-finally-end.

Given that the implementing language (Delphi, in this case) has SEH, can
I leverage this fact to add exception support in my Pascal-like
language? If so, where might I learn how to do this?

We discussed SEH both in general and also in Delphi, some time ago, in
c.l.p.d.misc. You'll find interface techniques to the Windows SEH in
System.pas and SysUtils.pas, from which you can build your own routines.
If you want your VM to be more platform independent, have a look at the
equivalent units in FreePascal.

If you don't allow for access to external code, which may rise
exceptions out of your control, you can implement any other exception
handling system in your VM. Then the good ole Basic OnError handling
might be a base to start from. Or you have a look at SEH in .NET.

In most cases your compiler(s) will have to produce appropriate code and
tables for the "H"andling part of SEH, the VM alone can not provide full
support for the asynchronous jumps into or around the except and finally
parts. This is why I mentioned the Basic OnError before, which in VB is
based on tables with the kind and range of the try, except and finally
parts, attached to every subroutine. These tables can be used to unwind
the stack after an exception occured, and to jump to the exception and
finally handlers, under full control of the VM, without further special
instructions or instruction sequences in the code itself. Apart from
this aspect the OnError and SEH models are quite incompatible, a VB
compiler for .NET has to produce very much code and lenghty tables, in
order to make OnError work in a SEH environment.


I'm willing to discuss details of SEH in this group, if John agrees, or
by e-mail, to some extent. The general part may be of wider interest, in
contrast to the Windows implementation details.

DoDi

.



Relevant Pages

  • Re: Try Finally...
    ... >different viewpoint between language constructs and S.E.H. constructs. ... SEH (Structured Exception Handling) is a stack based mechanism **administered ... Try/Except and Try/Finally are the car around the SEH engine. ... the exception handler registered in the stack. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Was not making tail recursion elmination a mistake?
    ... Not the language; the implementation techniques. ... there is a myth out there saying "don't use exception ... > handling, for it's dog slow". ...
    (comp.lang.lisp)
  • Re: Try Finally...
    ... >>handling, and Delphi's exception handling fulfills that definition. ... what administers SEH. ... but ultimately true exceptions are handled by Windows. ...
    (comp.lang.pascal.delphi.misc)
  • Re: HOWTO: Re-raise an error?
    ... Well, if you look at any of the scripts Microsoft ships with IIS, error handling is done by just checking Err.Number anywhere they expect something to have failed. ... From that perspective, examples of "real world exception handling" are documented, but there are more practical ways of doing it. ... Ideally, if you know what you're looking for in terms of another language, you could find out whether anyone's thought of a good way to simulate it in VBScript. ... ActiveState O'Reilly Python cookbook code samples ratings review ...
    (microsoft.public.scripting.vbscript)
  • Re: Exceptions
    ... I used to "believe" in checked exception handling, ... The *practical* effect of checked exceptions, ... Mind you, with the use of a non-garbage collected language like Ada, one would ...
    (comp.lang.ada)