Home arrow Zope arrow Page 3 - Exception Handling In DTML

Playing Catch - 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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

So that's what an error looks like. And now that you've seen what makes it tick, how about writing something to handle it?

Zope allows you to trap errors using the standard "try-catch" exception-handling combination...or, in the DTML world, <dtml-try> and <dtml-catch>. Here's what it looks like:


<dtml-try> execute this block <dtml-except err> execute this block if exception "err" is raised </dtml-try>
Take a look at this rewrite of the previous example, which incorporates a simple exception handler.

<dtml-try> <dtml-var CheckThisOut><dtml-except><b>Something bad happened</b></dtml-try>
Now, view this DTML Document and you'll see that the ugly error screen has disappeared; it's been replaced by a simpler (though not very useful) error message.



The first part of the code introduces you to the <dtml-try> block; this tag instructs Zope to try - literally - to execute the statements within the enclosing block.

<dtml-try> <dtml-var CheckThisOut>...</dtml-try>
The <dtml-except> tag sets up the exception handler, in the event that one is generated. This tag does the hard work of trapping the exception and suggesting an alternative path for Zope to proceed with.

<dtml-except> <b>Something bad happened</b>
If an exception is generated, the <dtml-except> segment of the code will be triggered, and Zope's default error handling mechanism will be overridden by the instructions in that code segment - in this case, displaying the text "Something bad happened".

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ZOPE ARTICLES

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