ErrorHandler

Type
Class
Namespace
Craft
Inherits
Craft\ErrorHandler » CErrorHandler (opens new window) » CApplicationComponent (opens new window) » CComponent (opens new window)
Implements
IApplicationComponent
Since
1.0

ErrorHandler handles uncaught PHP errors and exceptions.

It displays these errors using appropriate views based on the nature of the error and the mode the application runs at. It also chooses the most preferred language for displaying the error.

ErrorHandler uses two sets of views:

  • development templates, named as exception.php;
  • production templates, named as error<StatusCode>.php;

where <StatusCode> stands for the HTTP error code (e.g. error500.php). Localized templates are named similarly but located under a subdirectory whose name is the language code (e.g. zh_cn/error500.php).

Development templates are displayed when the application is in dev mode (i.e. craft()->config->get('devMode') = true). Detailed error information with source code are displayed in these templates. Production templates are meant to be shown to end-users and are used when the application is in production mode. For security reasons, they only display the error message without any sensitive information.

ErrorHandler looks for the templates from the following locations in order:

  • craft/templates/{siteHandle}/errors: when a theme is active.
  • craft/app/templates/errors
  • craft/app/framework/views

If the template is not found in a directory, it will be looked for in the next directory. The property {@link maxSourceLines} can be changed to specify the number of source code lines to be displayed in development views.

ErrorHandler is a core application component that can be accessed via {@link \CApplication::getErrorHandler()}.

See also http://craftcms.com

View source (opens new window)

# Public Properties

Property Description
$adminInfo (opens new window) string (opens new window) – The application administrator information (could be a name or email link).
$behaviors (opens new window) array (opens new window) – The behaviors that should be attached to this component.
$discardOutput (opens new window) boolean (opens new window) – Whether to discard any existing page output before error display.
$errorAction (opens new window) string (opens new window) – The route (eg 'site/error') to the controller action that will be used to display external errors.
$maxSourceLines (opens new window) integer (opens new window) – Maximum number of source code lines to be displayed.
$maxTraceSourceLines (opens new window) integer (opens new window) – Maximum number of trace source code lines to be displayed.

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__get() (opens new window) Returns a property value, an event handler list or a behavior based on its name.
__isset() (opens new window) Checks if a property value is null.
__set() (opens new window) Sets value of a component property.
__unset() (opens new window) Sets a component property to be null.
asa() (opens new window) Returns the named behavior object.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
attachEventHandler() (opens new window) Attaches an event handler to an event.
canGetProperty() (opens new window) Determines whether a property can be read.
canSetProperty() (opens new window) Determines whether a property can be set.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
detachEventHandler() (opens new window) Detaches an existing event handler.
disableBehavior() (opens new window) Disables an attached behavior.
disableBehaviors() (opens new window) Disables all behaviors attached to this component.
enableBehavior() (opens new window) Enables an attached behavior.
enableBehaviors() (opens new window) Enables all behaviors attached to this component.
evaluateExpression() (opens new window) Evaluates a PHP expression or callback under the context of this component.
getError() Returns the stored error, if there is one.
getEventHandlers() (opens new window) Returns the list of attached event handlers for an event.
getException() (opens new window) Returns the instance of the exception that is currently being handled.
getIsInitialized() (opens new window) Checks if this application component has been initialized.
handle() (opens new window) Handles the exception/error event.
hasEvent() (opens new window) Determines whether an event is defined.
hasEventHandler() (opens new window) Checks whether the named event has attached handlers.
hasProperty() (opens new window) Determines whether a property is defined.
init() (opens new window) Initializes the application component.
logException() Logs an exception in the same way that {@link \CWebApplication::handleException()} does.
raiseEvent() (opens new window) Raises an event.

# getError()

Returns the stored error, if there is one.

View source (opens new window)

Returns

array (opens new window), null (opens new window)

Signature

public array, null getError ( )

# logException()

Logs an exception in the same way that {@link \CWebApplication::handleException()} does.

View source (opens new window)

Arguments

Returns

void

Signature

public void logException ( Exception $exception )

# Protected Methods

Method Description
argumentsToString() (opens new window) Converts arguments array to its string representation
getExactTrace() (opens new window) Returns the exact trace where the problem occurs.
getHttpHeader() (opens new window) Return correct message for each known http error code
getVersionInfo() Returns server version information. If the site is in non-dev mode, an empty string is returned.
getViewFile() (opens new window) Determines which view file should be used.
getViewFileInternal() (opens new window) Looks for the view under the specified directory.
handleDbConnectionError() Handles DB connection errors.
handleError() Handles a PHP error.
handleException() Handles a thrown exception. Will also log extra information if the exception happens to by a MySql deadlock.
handleTwigError() Handles Twig syntax errors.
isAjaxRequest() (opens new window) Whether the current request is an AJAX (XMLHttpRequest) request.
isCoreCode() (opens new window) Returns a value indicating whether the call stack is from application code.
render() (opens new window) Renders the view.
renderError() Renders the exception information. This method will display information from current {@link error} value.
renderException() (opens new window) Renders the exception information.
renderSourceCode() (opens new window) Renders the source code around the error line.

# getVersionInfo()

Returns server version information. If the site is in non-dev mode, an empty string is returned.

View source (opens new window)

Returns

string (opens new window) – The server version information. Empty if in non-dev mode.

Signature

protected string getVersionInfo ( )

# handleDbConnectionError()

Handles DB connection errors.

View source (opens new window)

Arguments

Returns

null (opens new window)

Signature

protected null handleDbConnectionError ( Craft\DbConnectException $exception )

# handleError()

Handles a PHP error.

View source (opens new window)

Arguments

Returns

null (opens new window)

Signature

protected null handleError ( $event )

# handleException()

Handles a thrown exception. Will also log extra information if the exception happens to by a MySql deadlock.

View source (opens new window)

Arguments

Returns

null (opens new window)

Signature

protected null handleException ( $exception )

# handleTwigError()

Handles Twig syntax errors.

View source (opens new window)

Arguments

  • $exception (\Twig_Error)

Returns

null (opens new window)

Signature

protected null handleTwigError ( \Twig_Error $exception )

# renderError()

Renders the exception information. This method will display information from current {@link error} value.

View source (opens new window)

Signature

protected void renderError ( )