\Cake\ErrorExceptionRenderer

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.

Summary

Methods
Properties
Constants
__construct()
render()
__get()
__set()
__debugInfo()
No public properties found
No constants found
_unwrap()
_getController()
_customMethod()
_method()
_message()
_template()
_code()
_outputMessage()
_outputMessageSafe()
_shutdown()
$error
$controller
$template
$method
$request
N/A
No private methods found
No private properties found
N/A

Properties

$error

$error : \Exception

The exception being handled.

Type

\Exception

$template

$template : string

Template to render for Cake\Core\Exception\Exception

Type

string

$method

$method : string

The method corresponding to the Exception this object is for.

Type

string

$request

$request : \Cake\Http\ServerRequest|null

If set, this will be request used to create the controller that will render the error.

Type

\Cake\Http\ServerRequest|null

Methods

__construct()

__construct(\Exception  $exception, \Cake\Http\ServerRequest  $request = null) 

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.

\Cake\Http\ServerRequest $request

The request - if this is set it will be used instead of creating a new one

render()

render() : \Cake\Http\Response

Renders the response for the exception.

Returns

\Cake\Http\Response

The response to be sent.

__get()

__get(string  $name) : mixed

Magic accessor for properties made protected.

Parameters

string $name

Name of the attribute to get.

Returns

mixed

__set()

__set(string  $name, mixed  $value) : void

Magic setter for properties made protected.

Parameters

string $name

Name to property.

mixed $value

Value for property.

__debugInfo()

__debugInfo() : array

Returns an array that can be used to describe the internal state of this object.

Returns

array

_unwrap()

_unwrap(\Exception  $exception) : \Exception|\Error

Returns the unwrapped exception object in case we are dealing with a PHP 7 Error object

Parameters

\Exception $exception

The object to unwrap

Returns

\Exception|\Error

_getController()

_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

_customMethod()

_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

The response to send.

_method()

_method(\Exception  $exception) : string

Get method name

Parameters

\Exception $exception

Exception instance.

Returns

string

_message()

_message(\Exception  $exception, integer  $code) : string

Get error message.

Parameters

\Exception $exception

Exception.

integer $code

Error code.

Returns

string —

Error message

_template()

_template(\Exception  $exception, string  $method, integer  $code) : string

Get template for rendering exception info.

Parameters

\Exception $exception

Exception instance.

string $method

Method name.

integer $code

Error code.

Returns

string —

Template name

_code()

_code(\Exception  $exception) : integer

Get HTTP status code.

Parameters

\Exception $exception

Exception.

Returns

integer —

A valid HTTP error status code.

_outputMessage()

_outputMessage(string  $template) : \Cake\Http\Response

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()

_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

A response object that can be sent.

_shutdown()

_shutdown() : \Cake\Http\Response

Run the shutdown events.

Triggers the afterFilter and afterDispatch events.

Returns

\Cake\Http\Response

The response to serve.