Table of Contents

Class: Try qm/external/DocumentTemplate/DT_Try.py

Zope DTML Exception handling

usage:

<!--#try--> <!--#except SomeError AnotherError--> <!--#except YetAnotherError--> <!--#except--> <!--#else--> <!--#/try-->

or:

<!--#try--> <!--#finally--> <!--#/try-->

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, ( 'A try..finally combination cannot contain ' 'any other else, except or finally blocks', self.name )
ParseError, ( 'No more than one else block is allowed', self.name )
ParseError, ( 'Only one default exception handler ' 'is allowed', self.name )
ParseError, ( 'The else block should be the last block ' 'in a try tag', self.name )
  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 )

  render_try_finally 
render_try_finally ( self,  md )


Table of Contents

This document was automatically generated on Mon Jan 3 09:42:36 2005 by HappyDoc version 2.1