unrescue: fn();
if ( rescue("an exception", e) == HANDLER) { # normal execution code here unrescue(); } else { # handler code here }The next example is a complete program that demonstrates the behavior of exception handling by executing both the normal execution code and the handler code.
implement Excep; include "sys.m"; include "draw.m"; sys: Sys; print, raise, rescue, rescued, unrescue : import sys; Excep: module { init: fn(ctxt: ref Draw->Context, argv: list of string); }; init(ctxt: ref Draw->Context, argv: list of string) { sys = load Sys Sys->PATH; e := ref sys->Exception; if (rescue("an exception", e) == sys->HANDLER) { print("rescue: normal execution\n"); raise("an exception"); } else { print("rescue: exceptional execution\n"); print("e.name = %s\ne.mod = %s\ne.pc = %d\n", e.name, e.mod, e.pc); rescued(sys->ONCE, nil); } # This exception will not be handled print ("raise: %r\n"); raise ("an exception"); }