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. (https://cakefoundation.org)
License: MIT License
Location: Cake/Error/ExceptionRenderer.php

Properties summary

  • $controller public
    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 CakeException

Method Summary

  • __construct() public

    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.

  • _cakeError() protected
    Generic handler for the internal framework errors CakePHP can generate.
  • _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 CakeErrorController normally, or if an error is repeated a bare controller will be used.

  • _outputMessage() protected
    Generate the response using the controller object.
  • A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.

  • _shutdown() protected
    Run the shutdown events.
  • error400() public
    Convenience method to display a 400 series page.
  • error500() public
    Convenience method to display a 500 page.
  • pdoError() public
    Convenience method to display a PDOException.
  • render() public
    Renders the response for the exception.

Method Detail

__construct()source public

__construct( Exception|ParseError $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|ParseError $exception
Exception

_cakeError()source protected

_cakeError( CakeException $error )

Generic handler for the internal framework errors CakePHP can generate.

Parameters

CakeException $error
The exception to render.

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

_outputMessage()source protected

_outputMessage( string $template )

Generate the response using the controller object.

Parameters

string $template
The template to render.

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

_shutdown()source protected

_shutdown( )

Run the shutdown events.

Triggers the afterFilter and afterDispatch events.

error400()source public

error400( Exception $error )

Convenience method to display a 400 series page.

Parameters

Exception $error
The exception to render.

error500()source public

error500( Exception $error )

Convenience method to display a 500 page.

Parameters

Exception $error
The exception to render.

pdoError()source public

pdoError( PDOException $error )

Convenience method to display a PDOException.

Parameters

PDOException $error
The exception to render.

render()source public

render( )

Renders the response for the exception.

Properties detail

$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–2017 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/2.10/class-ExceptionRenderer.html