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 few words of caution are 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.