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;
Restrictions:
ON BAILOUT
section
ON BAILOUT
section must be at the bottom
BAILOUT()
cannot be called from within the ON BAILOUT
section
ON BAILOUT
section, program control cannot be transferred back to the procedure body
Pros:
BAILOUT()
call is translated into a JUMP instruction)
Cons: