Error Handler

You may use the Yee application’s error() method to specify a custom error handler to be invoked when an error or exception occurs. Custom error handlers are only invoked if application debugging is disabled.

A custom error handler should render a user-friendly message that mitigates user confusion. Similar to the Yee application’s notFound() method, the error() method acts as both a getter and a setter.

Set custom error handler

You may set a custom error handler by passing a callable into the Yee application's error() method as its first and only argument.

<?php
$app = new \Yee\Yee();
$app->error(function (\Exception $e) use ($app) {
    $app->render('error.php');
});

In this example, the custom error handler accepts the caught Exception as its argument. This allows you to respond appropriately to different exceptions.

Invoke custom error handler

Usually, the Yee application will automatically invoke the error handler when an exception or error occurs. However, you may also manually invoke the error handler with the Yee application’s error() method (without an argument).