{exception}
Throws a real PHP exception from the template, to exercise the error handling.
Syntax
{exception 'message'}
Parameters
-
message -
The message of the
Exceptionthat is thrown.
Description
{exception 'message'} executes throw new Exception ('message') inside the tag's handler. Where {error} reports an error the polite way, through padError(), this one behaves like PHP code that fails - a database library that throws, a division by zero - so it is the tag to try out how an application and its configuration deal with such a failure.
With $padErrorTry on (the default) the engine runs every tag handler inside a try guard: the exception is caught there and handed to the configured $padErrorAction, the same way as an error - under pad the request ends with status 500 and the report (the request id for a visitor who is not local), under log or ignore the page renders on without the tag. With the guards off it reaches PHP's exception handler: the error action records it and the request ends there as a failure, whatever the action.
It is mainly there for testing: the regression suites use it to prove that every error action and every guard behaves as documented. In application code, prefer {error}.
Examples
Throw from a page
The exception is caught by the tag guard and reported - the paragraph after it renders only under the log and ignore actions.
<p>before</p>
{exception 'thrown on purpose'}
<p>after</p>
Test an error page
Throw only when asked, to see the application's _errors/5xx.pad as a visitor would.
{if $simulate eq 'failure'}
{exception 'simulated failure'}
{/if}
<p>Everything works.</p>