Table of Contents

Class: Try Zope-2.2.1-src/lib/python/DocumentTemplate/DT_Try.py

Zope DTML Exception handling

usage:

or:

The DTML try tag functions quite like Python's try command.

The contents of the try tag are rendered. If an exception is raised, then control switches to the except blocks. The first except block to match the type of the error raised is rendered. If an except block has no name then it matches all raised errors.

The try tag understands class-based exceptions, as well as string-based exceptions. Note: the raise tag raises string-based exceptions.

Inside the except blocks information about the error is available via three variables.

error_type

This variable is the name of the exception caught.

error_value

This is the caught exception's value.

error_tb

This is a traceback for the caught exception.

The optional else block is rendered when no exception occurs in the try block. Exceptions in the else block are not handled by the preceding except blocks.

The try..finally form specifies a `cleanup` block, to be rendered even when an exception occurs. Note that any rendered result is discarded if an exception occurs in either the try or finally blocks. The finally block is only of any use if you need to clean up something that will not be cleaned up by the transaction abort code.

The finally block will always be called, wether there was an exception in the try block or not, or wether or not you used a return tag in the try block. Note that any output of the finally block is discarded if you use a return tag in the try block.

If an exception occurs in the try block, and an exception occurs in the finally block, or you use the return tag in that block, any information about that first exception is lost. No information about the first exception is available in the finally block. Also, if you use a return tag in the try block, and an exception occurs in the finally block or you use a return tag there as well, the result returned in the try block will be lost.

Original version by Jordan B. Baker.

Try..finally and try..else implementation by Martijn Pieters.

Methods   
__init__
find_handler
match_base
render
render_try_except
render_try_finally
  __init__ 
__init__ ( self,  blocks )

Exceptions   
ParseError
  find_handler 
find_handler ( self,  exception )

recursively search for a handler for a given exception

  match_base 
match_base (
        self,
        exception,
        name,
        )

  render 
render ( self,  md )

  render_try_except 
render_try_except ( self,  md )

Exceptions   
()
  render_try_finally 
render_try_finally ( self,  md )


Table of Contents

This document was automatically generated on Mon Sep 4 07:33:06 2000 by HappyDoc version r0_6