You can add primitive error-handling to your templates via the special "on-error" attribute, which allows you to specify a simple error message that is displayed when TAL encounters an error. Consider the following example: In this case, since my code requires the "size", "face" and "color" input variables to be specified as input parameters via the URL (notice that I have not used the "default" condition here, as I did in the previous example), an error will be generated if these variables are not present. However, rather than displaying the standard Zope error message, ![]() I can intercept the error with TAL's "on-error" attribute, and replace it with my own, simpler error message. ![]() "on-error" attributes are processed in a hierarchical manner, with TAL recursing upwards from the source of the error until it finds an "on-error" error handler. In the following example, even though the error is generated by the innermost <font> element, the error message generated comes from the outermost <div> element. This is obviously a primitive example - you can do some pretty complex things with the "on-error" attribute. Take a look at http://www.zope.org/Wikis/DevSite/Projects/ZPT/RenderErrorHandlingStrategies for more information.
blog comments powered by Disqus |