Home arrow Zope arrow Page 7 - Exception Handling In DTML

The Final Solution - Zope

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.

  1. Exception Handling In DTML
  2. Anatomy Class
  3. Playing Catch
  4. Being Verbose
  5. All For One...
  6. ...And One For All
  7. The Final Solution
  8. Raising The Bar
  9. Pre-Packaged Python
  10. Endzone
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 1
August 13, 2002

print this article


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:

<dtml-try> execute this block <dtml-finally> execute this block if exceptions are generated </dtml-try>
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-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 Goodbye!
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.

>>> More Zope Articles          >>> More By Harish Kamath, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Creating Zope Products
- Plone Content Types With Archetypes
- Flat User Management in Zope
- Creating Basic Zope Applications
- Getting started with Zope for Linux and Sola...
- ZPT Basics (part 4)
- ZPT Basics (part 3)
- ZPT Basics (part 2)
- ZPT Basics (part 1)
- Exception Handling In DTML
- DTML Basics (part 4)
- DTML Basics (part 3)
- DTML Basics (part 2)
- DTML Basics (part 1)
- Using Zope With Apache

Developer Shed Affiliates


Dev Shed Tutorial Topics: