Previous Chapter | Next Chapter | Up | Next Section | Contents

Reporting Errors with the dtml-raise Tag


In many applications, inputs or other variables need to be checked for validity before actions are performed. DTML provides a convenient means of performing validity checks by using the dtml-raise tag in combination with the if tag. Validity checks are performed with the if tag. The dtml-raise tag is used to report the errors.

The dtml-raise tag has a type attribute for specifying an error type. Like the standard name attribute, the attribute name of the type attribute may be omitted. The error type is a short descriptive name for the error. In addition, there are some standard types, like " Unauthorized " and " Redirect " that are returned as HTTP errors. In particular, " Unauthorized " errors cause a log-in prompt to be displayed on the user's browser.

The dtml-raise tag is a non-empty tag. The source enclosed by the dtml-raise tag is rendered to create an error message. If the rendered text contains any HTML markup, then Zope will display the text as an error message on the browser, otherwise a generic error message is displayed.

Here is a dtml-raise tag example:

<dtml-if "balance >= debit_amount">
<dtml-call "debitAccount(account)">
Your account, <dtml-var account>, has been debited.
<dtml-else>
<dtml-raise type="Insufficient funds">
There is not enough money in account <dtml-account>
to cover the requested debit amount.<p>
</dtml-raise>
</dtml-if>

The dtml-raise tag causes a Zope error to occur. However, there is an important side effect to this error that causes any changes made by a web request to be ignored, assuming that a transactional persistence mechanism, like the Zope Database is being used.

Previous Chapter | Next Chapter | Up | Next Section | Contents