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

Reporting Errors with the 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 raise tag in combination with the if tag. Validity checks are performed with the if tag. The raise tag is used to report the errors.

The 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 raise tag is an non-empty tag. The source enclosed by the 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 raise tag example:

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

The 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