{error}
Raises a PAD error from the template, handled as the configured error action says.
Syntax
{error 'message'}
Parameters
-
message -
The text of the error. The report shows it as
PAD: message, with the template position of the tag.
Description
{error 'message'} calls padError() - the same function the engine uses for its own errors - from a template. What happens next is up to $padErrorAction in _config/config.php:
-
pad(the default): the request ends with status 500 and the error report - the message, where in the template it stands, the stack - for a local request; any other visitor gets the request id, or the application's_errors/500.pad, while the report is logged. -
stopandexit: the request ends with status 500, without the report page. -
dump: the full dump is written toDATA/dumps/and the error logged; the page goes on. -
log: the error is logged and the page goes on;ignore: the page goes on and nothing is logged. -
bootandphp: the boot handler, or PHP's own exception handling, takes over.
In every case the application's _events/error.php hook runs first, with $error, $file and $line. When the request survives, the tag itself renders nothing: padError() returns FALSE.
Use it to stop on a state a page must never reach - an unknown value in a {case}, a required row that is not there. For a check that only test runs should hold the page to, use {assert}; to end the request quietly, {exit}; to throw a real PHP exception instead, {exception}.
Examples
A value that must not occur
An unknown status ends the request with a report naming it, instead of rendering an empty cell.
{case $status}
{when 'open'} <span class="open">Open</span>
{when 'paid'} <span class="paid">Paid</span>
{when 'shipped'} <span class="done">Shipped</span>
{else} {error 'unknown order status'}
{/case}
A required row
No customer for the order: the error is raised, the event hook and the error action take it from there.
{if not $customer}
{error 'order without a customer'}
{/if}
<h2>{$customer.name}</h2>
See also
- {exception} Throws a real PHP exception from the template, to exercise the error handling.
- {assert} A condition a test run holds the page to; silent everywhere else.
- {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.