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.
And that just about covers it. In this article, I took you on a guided tour of exception handling in DTML, demonstrating how the and blocks can be used to trap and resolve errors in script execution. I showed you how the statement could be used to handle different exceptions differently, or be set up to catch all errors in a generic manner.
I also explained a variant, the <dtml-finally> statement, and demonstrated how it could be nested within a set of <dtml-try> blocks to trigger specific code segments whenever an exception occurs. Finally, I showed you how to create your own custom exceptions via <dtml-raise>, and provided you with a quick look at some of the built-in exceptions that come with Zope.
In case you'd like to learn more about these topics, you should consider visiting the following links:
Note: All examples in this article have been tested on Linux/i586 with Zope 2.5.0. Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article. YMMV!