Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

Local Exception Handling

WiP.LocalExceptionHandling History

Hide minor edits - Show changes to markup

2009-11-13 04:57 by benjk -
Changed line 42 from:

Benefits:

to:

Pros:

Added line 44:
  • helps to avoid cache misses due to large sections of inlined error handling code
Deleted line 46:
  • helps to avoid cache misses due to large sections of inlined error handling code
Added lines 48-50:

Cons:

  • adds an additional feature
2009-11-13 03:24 by benjk -
Changed line 28 from:
to:
2009-11-13 03:20 by benjk -
Changed lines 34-47 from:

END Foobar;@]

to:

END Foobar;@]

Restrictions:

  • a procedure can only have one ON BAILOUT section
  • if present, the ON BAILOUT section must be at the bottom
  • BAILOUT() cannot be called from within the ON BAILOUT section
  • once inside the ON BAILOUT section, program control cannot be transferred back to the procedure body

Benefits:

  • increases clarity by emphasising the normal (error-free) flow of a program
  • does not incur any cost in the general case (when no exception is raised)
  • raising an exception incurs minimal cost (typically one machine cycle only)
  • helps to avoid cache misses due to large sections of inlined error handling code
  • very easy to implement (a BAILOUT() call is translated into a JUMP instruction)
2009-11-13 02:53 by benjk - An idea for a simple zero cost exception handling mechanism
Added lines 1-34:
PROCEDURE Foobar( p1, p2, p3 : T ) : Status;
BEGIN

IF foo = NIL THEN
    BAILOUT(FooNilError); (* raise local exception *)
ELSE
     doFooStuff;
END;

DoBar(bar);
IF bar = 0 THEN
    BAILOUT(BarZeroError); (* raise local exception *)
ELSE
    doBarStuff;
END;

DoBaz(baz);
IF baz > MAXBAZ THEN
    BAILOUT(BazOverflowError); (* raise local exception *)
ELSE
    doBazStuff;
END;

RETURN Success;

(* handle local exceptions *)
ON BAILOUT
   BazOverflowError:
      UndoBarStuff;
   BarZeroError :
      UndoFooStuff;
   FooNilError :
      RETURN Failure;
END Foobar;