Ever wondered if there was a way to stop Zope from barfing error messages all over your screen when one of your scripts crashes and burns? Well, guess what - there is! Meet the and tags, which can be used to trap and resolve errors in script execution.
Thus far, you've been working with DTML's built-in exceptions, which can handle most logical or syntactical expressions. However, DTML also allows you to get creative with exceptions, by generating your own custom exceptions if the need arises.
This is accomplished via the <dtml-raise> tag, used to raise errors which can be detected and resolved by the <dtml-try> family of exception handlers. The <dtml-raise> tag needs to be passed an exception name, and an optional descriptive string. When the exception is raised, this exception name and description will be made available to the defined exception handler.
Consider the following script, which demonstrates:
In this case, Zope will raise the user-defined exception, AccessError, whenever the conditional expression specified evaluates as false. This exception may be caught by a <dtml-try> block, or by the default error handler (as demonstrated in the output screenshot below).