Class ExceptionRenderer

Exception Renderer.

Captures and handles all unhandled exceptions. Displays helpful framework errors when debug > 1. When debug < 1 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 in one of a few ways:

  • Create an AppController::appError();
  • Create a subclass of ExceptionRenderer and configure it to be the Exception.renderer

Using AppController::appError();

This controller method is called instead of the default exception handling. It receives the thrown exception as its only argument. You should implement your error handling in that method.

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 core.php, with Configure::write('Exception.renderer', 'MyClass'); You should place any custom exception renderers in app/Lib/Error.

Package: Cake\Error
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Located at Cake/Error/ExceptionRenderer.php

Method Detail

__constructsource public

__construct( Exception $exception )

Creates the controller to perform rendering on the error response. If the error is a CakeException 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

_cakeErrorsource protected

_cakeError( CakeException $error )

Generic handler for the internal framework errors CakePHP can generate.

Parameters

CakeException $error
The exception to render.

_getControllersource protected

_getController( Exception $exception )

Get the controller instance to handle the exception. Override this method in subclasses to customize the controller used. This method returns the built in CakeErrorController normally, or if an error is repeated a bare controller will be used.

Parameters

Exception $exception
The exception to get a controller for.

Returns

Controller
Controller

_outputMessagesource protected

_outputMessage( string $template )

Generate the response using the controller object.

Parameters

string $template
The template to render.

_outputMessageSafesource 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

error400source public

error400( Exception $error )

Convenience method to display a 400 series page.

Parameters

Exception $error
The exception to render.

error500source public

error500( Exception $error )

Convenience method to display a 500 page.

Parameters

Exception $error
The exception to render.

pdoErrorsource public

pdoError( PDOException $error )

Convenience method to display a PDOException.

Parameters

PDOException $error
The exception to render.

rendersource public

render( )

Renders the response for the exception.

Properties summary

$controllersource

public Controller

Controller instance.

null

$errorsource

public Exception

The exception being handled.

null

$methodsource

public string

The method corresponding to the Exception this object is for.

''

$templatesource

public string

template to render for CakeException

''

© 2005–2016 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.
http://api.cakephp.org/2.7/class-ExceptionRenderer.html