{exception}

Throws a real PHP exception from the template, to exercise the error handling.

Debugging and errors Single tags

Syntax

{exception 'message'}

Parameters

message
The message of the Exception that 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.

Templateexamples/exception/1-throw.src
<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.

Templateexamples/exception/2-in-a-branch.src
{if $simulate eq 'failure'}
  {exception 'simulated failure'}
{/if}
<p>Everything works.</p>

See also

  • {error} Raises a PAD error from the template, handled as the configured error action says.
  • {exit} Ends the request at once, with an empty body - the PAD way to stop instead of PHP's exit.
  • {dump} Stops the request and shows the debug dump of the engine's state at that point.