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.
Most of what you've just learned also applies to DTML's other exception-handling construct, the "try-finally" statement. The "try-finally" statement block differs from "try-except-else" in that it merely detects errors; it does not provide for a mechanism to resolve them. It is typically used to ensure that certain statements are always executed when an error (regardless of type) is encountered.
Here's what it looks like:
execute this block
execute this block if exceptions
If an exception is encountered when running the code within the <dtml-try> block, Zope will stop execution at that point; jump to the <dtml-finally> block; execute the statements within it; and then pass the exception upwards, to the parent <dtml-try> block, if one exists, or to the default handler, which terminates the program.
Take a look at the next example to see how this works:
<dtml-try><dtml-var CheckThisOut><dtml-except KeyError><b>No value assigned to the variable: <dtml-var error_value><br></b></dtml-try><dtml-finally><i>Goodbye!</i></dtml-try>
Here's the output:
No value assigned to the variable: CheckThisOut
It's important to note that the code in the <dtml-finally> block - actually part of the outer <dtml-try> block - will be executed even if errors are encountered in the inner <dtml-try> block.