Class ExceptionRenderer
Exception Renderer.
Captures and handles all unhandled exceptions. Displays helpful framework errors when debug is true. When debug is false a ExceptionRenderer 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.
Properties summary
- $controller protected
\Cake\Controller\Controller
Controller instance.
- $error protected
\Throwable
The exception being handled.
- $method protected
string
The method corresponding to the Exception this object is for.
- $request protected
\Cake\Http\ServerRequest|null
If set, this will be request used to create the controller that will render the error.
- $template protected
string
Template to render for Cake\Core\Exception\Exception
Method Summary
- __debugInfo() public
Returns an array that can be used to describe the internal state of this object.
- _outputMessageSafe() protected
A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.
Method Detail
__construct() public
__construct(\Throwable $exception, ?\Cake\Http\ServerRequest $request)
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
-
\Throwable
$exception Exception.
-
\Cake\Http\ServerRequest
$request optional The request if this is set it will be used instead of creating a new one.
__debugInfo() public
__debugInfo()
Returns an array that can be used to describe the internal state of this object.
Returns
array
_code() protected
_code(\Throwable $exception)
Get HTTP status code.
Parameters
-
\Throwable
$exception Exception.
Returns
int
A valid HTTP error status code.
_customMethod() protected
_customMethod(string $method, \Throwable $exception)
Render a custom error method/template.
Parameters
-
string
$method The method name to invoke.
-
\Throwable
$exception The exception to render.
Returns
\Cake\Http\Response
The response to send.
_getController() protected
_getController()
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(\Throwable $exception, int $code)
Get error message.
Parameters
-
\Throwable
$exception Exception.
-
int
$code Error code.
Returns
string
Error message
_method() protected
_method(\Throwable $exception)
Get method name
Parameters
-
\Throwable
$exception Exception instance.
Returns
string
_outputMessage() protected
_outputMessage(string $template)
Generate the response using the controller object.
Parameters
-
string
$template The template to render.
Returns
\Cake\Http\Response
A response object that can be sent.
_outputMessageSafe() protected
_outputMessageSafe(string $template)
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
A response object that can be sent.
_shutdown() protected
_shutdown()
Run the shutdown events.
Triggers the afterFilter and afterDispatch events.
Returns
\Cake\Http\Response
The response to serve.
_template() protected
_template(\Throwable $exception, string $method, int $code)
Get template for rendering exception info.
Parameters
-
\Throwable
$exception Exception instance.
-
string
$method Method name.
-
int
$code Error code.
Returns
string
Template name
clearOutput() protected
clearOutput()
Clear output buffers so error pages display properly.
render() public
render()
Renders the response for the exception.
Returns
\Cake\Http\Response
The response to be sent.
Property Detail
$controller protected
Controller instance.
Type
\Cake\Controller\Controller
$error protected
The exception being handled.
Type
\Throwable
$method protected
The method corresponding to the Exception this object is for.
Type
string
$request protected
If set, this will be request used to create the controller that will render the error.
Type
\Cake\Http\ServerRequest|null
$template protected
Template to render for Cake\Core\Exception\Exception
Type
string
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.Error.ExceptionRenderer.html