The Exception Objects

The exception objects include a zero and one parameter version of Code.Exception and the Code.TryCatch objects. Additional objects for exception handling can be defined by the user. The exception objects are typed with the Null type.

A simple example of a clause that generates an exception would be:

A function containing this clause will return the Exception object if the parameter passed in has zero in the denominator.

There is also a one parameter version of the Exception object, but users can create additional exception objects as needed. See Creating an Object Definition for more information. The only requirement for these exception objects is that the final type in the type definition must be the Null type in order for the exception to propagate upward as expected. See Null Typed Objects for an explanation.

The TryCatch object behaves in a way that is similar to a try/catch in other programming languages. For example:

Note that the "catch" term is implemented as a pattern match, so this example will "catch" any one parameter Exception object returned by the code inside of the "try" block.

In addition, the "catch" term isn't necessarily limited to just exception objects. In fact, you can "catch" pretty much any expression, though there are probably better ways to handle other cases.