File exception.icn |
This file contains a simple exception handling system for Unicon.
Example use of the classes in this package:
case x := Try().call{ f(1) } of { Try().isException(x): write(x.getMessage(),": ",x.getLocation()) default: write("x is ",x) }or, alternatively:
case x := Try().call{ f(1) } of { Try().catch(): { x := Try().getException() write(x.getMessage(),": ",x.getLocation()) } default: write("x is ",x) }The Exception itself can be thrown as easily as:
Exception().throw("format error")
There are some limitations to this implementation of exceptions. For example, the stack trace associated with an exception is constrained to the current co-expression stack. Also, the code executed in the Try().call{...} clause is a bounded expression that can produce at most one result.
Author: Steve Wampler (sbw@tapestry.tucson.az.us)
This file is in the public domain.
This file is part of the exception package.
Source code.