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 a 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
.
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Error/ExceptionRenderer.php
Properties summary
-
$controller
publicController instance. -
$error
publicException
The exception being handled. -
$method
publicstring
The method corresponding to the Exception this object is for. -
$template
publicstring
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. -
_outputMessageSafe() protected
A safer way to render error messages, replaces all helpers, with basics and doesn't call component methods.
-
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() 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
Returns
Return void or value returned by controller's
appError()
function_cakeError() protected ¶
_cakeError( CakeException
$error )
Generic handler for the internal framework errors CakePHP can generate.
Parameters
-
CakeException
$error
_getController() 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
_outputMessage() protected ¶
_outputMessage( string $template )
Generate the response using the controller object.
Parameters
- string $template
- The template to render.
_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
error400() public ¶
error400( Exception $error )
Convenience method to display a 400 series page.
Parameters
- Exception $error
error500() public ¶
error500( Exception $error )
Convenience method to display a 500 page.
Parameters
- Exception $error
pdoError() public ¶
pdoError( PDOException $error )
Convenience method to display a PDOException.
Parameters
- PDOException $error