Package qm :: Package external :: Package DocumentTemplate :: Module DT_Try :: Class Try
[hide private]
[frames] | no frames]

Class Try

source code

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.

Instance Methods [hide private]
 
__init__(self, blocks) source code
 
render(self, md) source code
 
render_try_except(self, md) source code
 
render_try_finally(self, md) source code
 
find_handler(self, exception)
recursively search for a handler for a given exception
source code
 
match_base(self, exception, name) source code
 
__call__(self, md) source code
Class Variables [hide private]
  name = 'try'
  blockContinuations = ('except', 'else', 'finally')
  finallyBlock = None
hash(x)
  elseBlock = None
hash(x)