Home arrow Zope arrow Page 6 - Exception Handling In DTML

...And One For All - 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


Now, the <dtml-try> statement can only deal with exceptions that it knows about. What about the ones the developer can't predict?

DTML also allows you to specify a catch-all exception handler, one which handles *any* type of exception generated - simply omit the exception name from the <dtml-except> statement. The following code snippet illustrates this technique:

<dtml-try> <dtml-var alpha> divided by <dtml-var beta> is <dtml-var expr="_.int(alpha)/_.int(beta)" >.<br> <dtml-except> <b>Something bad happened. Call 911.</b> </dtml-try>
You can even combine this with exception handlers for specific exceptions.

<dtml-try> <dtml-var alpha> divided by <dtml-var beta> is <dtml-varexpr="_.int(alpha)/_.int(beta)" >.<br><dtml-except KeyError><b>Missing variable.</b><dtml-except ValueError><b>Illegal value.</b><dtml-except><b>Something bad happened. Call 911.</b></dtml-try>
This way, when an exception occurs, Zope will first check to see if an exception handler has been defined for that exception type. If so, the appropriate handler is invoked; if not, the exception is routed to the catch-all handler, which displays a generic error message.

>>> 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: