Most of what you've just learned also applies to DTML's other exception-handling construct, the "try-finally" statement. The "try-finally" statement block differs from "try-except-else" in that it merely detects errors; it does not provide for a mechanism to resolve them. It is typically used to ensure that certain statements are always executed when an error (regardless of type) is encountered. Here's what it looks like: If an exception is encountered when running the code within the <dtml-try> block, Zope will stop execution at that point; jump to the <dtml-finally> block; execute the statements within it; and then pass the exception upwards, to the parent <dtml-try> block, if one exists, or to the default handler, which terminates the program. Take a look at the next example to see how this works: Here's the output: It's important to note that the code in the <dtml-finally> block - actually part of the outer <dtml-try> block - will be executed even if errors are encountered in the inner <dtml-try> block.
blog comments powered by Disqus |