"Casse Hugues" <casse@netcourrier.com> writes:
|> I uses the POSIX C functions setjmp()/lonjmp() from <setjmp.h> for
|> emulating exceptions in my C programs. These functions stores the
|> registers in a memory and restore it when the jump is performed. This is
|> the faster way to implement it I know (in C).

Unfortunately, that only appears to work. The C standard states
explicitly that they will not work for real exception handling, though
you can get them to work for language-created exceptions. Effectively
that means that SYSTEM exceptions (e.g. SIGINT or even I/O errors)
need system-specific code and Assembler.

|> But you must think about memory management because these functions
|> handle only the register and do not know anything about memory. Usually,
|> fast exception handling requires either special memory structure, or
|> garbage collection.

And other things, such as any global mode you set in the library. You
can easily use an extra argument for such state (it is how many
systems did it in the past), but you must pass that down through all
functions, whether they use exceptions or not. There are
optimisations, but they are messy and tricky to get right.