Class: Try | qm/external/DocumentTemplate/DT_Try.py | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Zope DTML Exception handlingusage: <!--#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 Inside the except blocks information about the error is available via three variables.
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.
|