Class ExceptionRenderer
Exception Renderer.
Captures and handles all unhandled exceptions. Displays helpful framework errors when debug is true. When debug is false a CakeException will render 404 or 500 errors. If an uncaught exception is thrown and it is a type that ExceptionHandler does not know about it will be treated as a 500 error.
Implementing application specific exception rendering
You can implement application specific exception handling by creating a subclass of
ExceptionRenderer and configure it to be the exceptionRenderer
in config/error.php
Using a subclass of ExceptionRenderer
Using a subclass of ExceptionRenderer gives you full control over how Exceptions are rendered, you can configure your class in your config/app.php.
Property Summary
-
$controller public
Cake\Controller\Controller
Controller instance.
-
$error public
Exception
The exception being handled.
-
$method public
string
The method corresponding to the Exception this object is for.
-
$template public
string
Template to render for Cake\Core\Exception\Exception
Method Summary
-
__construct() public
Creates the controller to perform rendering on the error response. If the error is a Cake\Core\Exception\Exception it will be converted to either a 400 or a 500 code error depending on the code used to construct the error.
-
_code() protected
Get an error code value within range 400 to 506
-
_customMethod() protected
Render a custom error method/template.
-
_getController() protected
Get the controller instance to handle the exception. Override this method in subclasses to customize the controller used. This method returns the built in
ErrorController
normally, or if an error is repeated a bare controller will be used. -
_message() protected
Get error message.
-
_method() protected
Get method name
-
_outputMessage() protected
Generate the response using the controller object.
-
_outputMessageSafe() protected
A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.
-
_shutdown() protected
Run the shutdown events.
-
_template() protected
Get template for rendering exception info.
-
_unwrap() protected
Returns the unwrapped exception object in case we are dealing with a PHP 7 Error object
-
render() public
Renders the response for the exception.
Method Detail
__construct() ¶ public
__construct(Exception $exception)
Creates the controller to perform rendering on the error response. If the error is a Cake\Core\Exception\Exception it will be converted to either a 400 or a 500 code error depending on the code used to construct the error.
Parameters
-
Exception
$exception Exception.
_code() ¶ protected
_code(Exception $exception): int
Get an error code value within range 400 to 506
Parameters
-
Exception
$exception Exception.
Returns
int
_customMethod() ¶ protected
_customMethod(string $method, Exception $exception): Cake\Http\Response
Render a custom error method/template.
Parameters
-
string
$method The method name to invoke.
-
Exception
$exception The exception to render.
Returns
Cake\Http\Response
_getController() ¶ protected
_getController(): Cake\Controller\Controller
Get the controller instance to handle the exception.
Override this method in subclasses to customize the controller used.
This method returns the built in ErrorController
normally, or if an error is repeated
a bare controller will be used.
Returns
Cake\Controller\Controller
_message() ¶ protected
_message(Exception $exception, int $code): string
Get error message.
Parameters
-
Exception
$exception Exception.
-
int
$code Error code.
Returns
string
_method() ¶ protected
_method(Exception $exception): string
Get method name
Parameters
-
Exception
$exception Exception instance.
Returns
string
_outputMessage() ¶ protected
_outputMessage(string $template): Cake\Http\Response
Generate the response using the controller object.
Parameters
-
string
$template The template to render.
Returns
Cake\Http\Response
_outputMessageSafe() ¶ protected
_outputMessageSafe(string $template): Cake\Http\Response
A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.
Parameters
-
string
$template The template to render.
Returns
Cake\Http\Response
_shutdown() ¶ protected
_shutdown(): Cake\Http\Response
Run the shutdown events.
Triggers the afterFilter and afterDispatch events.
Returns
Cake\Http\Response
_template() ¶ protected
_template(Exception $exception, string $method, int $code): string
Get template for rendering exception info.
Parameters
-
Exception
$exception Exception instance.
-
string
$method Method name.
-
int
$code Error code.
Returns
string
_unwrap() ¶ protected
_unwrap(Exception $exception): ExceptionError
Returns the unwrapped exception object in case we are dealing with a PHP 7 Error object
Parameters
-
Exception
$exception The object to unwrap
Returns
ExceptionError
render() ¶ public
render(): Cake\Http\Response
Renders the response for the exception.
Returns
Cake\Http\Response