Next: 1.10 Introspection Up: 1. Onyx Language Tutorial Previous: 1.8.2 Modules Contents Index

# 1.9 Error handling

Onyx includes a powerful generic error handling mechanism that can be extended and customized at several levels. The throw procedure is used to throw an error, and virtually every aspect of the error handling machinery can be customized, extended, or replaced, since it is all written in Onyx.

Errors have names, with which error handlers can be associated in errordict. errordict's handleerror procedure can be modified or replaced. In fact, with some care, an entirely custom errordict can be defined, then undefined once it is no longer needed.

Following is the standard idiom for setting up and tearing down custom error handling:

    # Set up custom error handling...
    {
        # Do error-prone stuff...
    } stopped {
        # An error occurred.  Do additional cleanup...
    } if
    # Restore error handling machinery...

The possibilities are extensive. However, a word of caution is in order. If you mess something up in the error handling machinery, bad things will happen, and you will have a terrible time debugging the problem. Be careful.