4.11. catch
The page content contained within the [catch label][/catch] block executes if the correspondingly labelled try block fails.
You can also return a result based on the error message caught in the try block with paired subtags, like this:
[error message]body text[/error message]
Note that this feature excises all tag/endtag pairs if interpolation is turned off, so the catch tag interpolates by default.
See also [try].
4.11.1. Summary
[try my_label] Body text to return if no error [/try] . . . [catch label=my_label other_named_attributes] [/Pattern matching error message 1/] Return this if error 1 occurs [/Pattern matching error message 1/] [/Pattern matching error message 2/] Return this if error 2 occurs, etc. [/Pattern matching error message 2/] Default body text to process if try block caused an error [/catch]
Parameters | Description | Default |
label | The label shared by the paired try and catch blocks | 'default' |
Attributes | Default |
interpolate | Yes |
reparse | Yes |
Other_Characteristics | |
Invalidates cache | No |
Container tag | Yes |
Has Subtags |
[/Error message text] |
Tag expansion example
Ignoring whitespace, the following would return division result if successful, 0 on a division by zero, or an error message:
[set divisor]0[/set] [try label=div] [perl] eval(1 / [scratch divisor]) [/perl] [/try] [catch div] [/Illegal division by zero/] 0 [/Illegal division by zero/] [/eval "string" trapped by operation mask/] Perl Safe error [/eval "string" trapped by operation mask/] Other division error [/catch] --- Perl Safe error
ASP-like Perl call:
$Tag->catch( { label => I<'my_label'>, }, $body );
or similarly with positional parameters,
$Tag->catch($label, $attribute_hash_reference, $body);
4.11.1.1. See Also
[catch]
Attributes | Default |
interpolate (reparse) | No |
Other_Characteristics | |
Invalidates cache | No |
Container tag | No |
Has Subtags | No |
Nests | Yes |
Tag expansion example:
[catch] --- TAG RESULT
ASP-like Perl call:
$Tag->catch( { }, $body );
or similarly with positional parameters,
$Tag->catch(, $attribute_hash_reference, $body);
4.11.2. Description
The page content contained within the [catch label][/catch] block executes if the correspondingly labelled try block fails. The catch block executes in place on the page if triggered (i.e., it does not return its result in place of the try block).
You can also return a result based on the error message caught in the try block with paired subtags, like this:
[/error message/]special catch block for the error[/error message/]
The error message to use in the special block will generally be part of the entry the error generates in your error log. For example, a division by zero error generates something like the following in the error log:
127.0.0.1 4cU3Pgsh:127.0.0.1 - [24/May/2001:14:45:07 -0400]\ tag /cgi-bin/tag72/tag Safe: Illegal division by zero\ at (eval 526) line 2.
(note that trailing backslashes in the example indicate a continued line).
4.11.2.1. label
This is the label specifying the corresponding [try block. Defaults to 'default'.