![]() |
| > Home > Documentation > Latest documentation > Interchange tags > catch |
|
catchThe page content contained within the [catch]...[/catch] block will be executed if a runtime error is detected in the correspondingly-labelled [try]...[/try] block. Summary
ExamplesTag usage exampleThe [try] tag will run a block of Interchange tags and trap any errors found.
The [catch] tag can then handle any errors that were trapped by the [try].
DescriptionThe 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 sub-tags, like this:
The error message to use in the special block will generally be part of the entry the error generates in the error.log file. For example, a division by zero error would generate something like the following in the error log file:
Note that this feature excises all tag/end-tag pairs if interpolation is turned off, so the catch tag interpolates its body text by default. Ignoring whitespace, the following would return the result if the division was successful, 0 on a division by zero or an error message:
The "$$ERROR$$" token will be replaced with the actual error message that was caught. If no error was detected then the optional [else] block will be used. If there was an error then the [else] block will be discarded. ParameterslabelThis is the label specifying the corresponding [try] block. Defaults to "default". error_scratchThe scratchpad variable, named by this parameter, will be set true if an error was caught. error_setAssociate the error with the named form variable. See the [error] tag's set parameter, which is called upon to create the association. hideSetting hide=1 suppresses the tag's return value, which can be useful with the set attribute.
|
| Home | Legal nonsense | Privacy policy | Contact us |