## Class TErrorHandler

Description

TErrorHandler class

TErrorHandler handles all PHP user errors and exceptions generated during servicing user requests. It displays these errors using different templates and if possible, using languages preferred by the client user. Note, PHP parsing errors cannot be caught and handled by TErrorHandler.

The templates used to format the error output are stored under System.Exceptions. You may choose to use your own templates, should you not like the templates provided by Prado. Simply set ErrorTemplatePath to the path (in namespace format) storing your own templates.

There are two sets of templates, one for errors to be displayed to client users (called external errors), one for errors to be displayed to system developers (called internal errors). The template file name for the former is error[StatusCode][-LanguageCode].html, and for the latter it is exception[-LanguageCode].html, where StatusCode refers to response status code (e.g. 404, 500) specified when THttpException is thrown, and LanguageCode is the client user preferred language code (e.g. en, zh, de). The templates error.html and exception.html are default ones that are used if no other appropriate templates are available. Note, these templates are not Prado control templates. They are simply html files with keywords (e.g. %%ErrorMessage%%, %%Version%%) to be replaced with the corresponding information.

By default, TErrorHandler is registered with TApplication as the error handler module. It can be accessed via TApplication::getErrorHandler(). You seldom need to deal with the error handler directly. It is mainly used by the application object to handle errors.

TErrorHandler may be configured in application configuration file as follows <module id="error" class="TErrorHandler" ErrorTemplatePath="System.Exceptions" />

- since: 3.0
- version: $Id: TErrorHandler.php 2357 2008-01-04 22:46:57Z xue $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /Exceptions/TErrorHandler.php (line 52)

    TComponent
       |
       --TApplicationComponent
          |
          --TModule
             |
             --TErrorHandler

Direct descendents

Class | Description
--- | ---
TCallbackErrorHandler | TCallbackErrorHandler class.

Class Constant Summary
ERROR_FILE_NAME = 'error'
EXCEPTION_FILE_NAME = 'exception'
SOURCE_LINES = 12
Method Summary
void displayException (Exception $exception)
string getErrorTemplate (integer $statusCode, Exception $exception)
string getErrorTemplatePath ()
string getExceptionTemplate (Exception $exception)
void handleError (mixed $sender, mixed $param)
void handleExternalError (integer $statusCode, Exception $exception)
void handleRecursiveError (Exception $exception)
void init (TXmlElement $config)
void setErrorTemplatePath (string $value)
Methods
displayException (line 202)

Displays exception information.

Exceptions are displayed with rich context information, including the call stack and the context source code. This method is only invoked when application is in Debug mode.

- access: protected

void displayException (Exception $exception)

- Exception $exception: exception instance

Redefined in descendants as:

- TCallbackErrorHandler::displayException() : Displays the exceptions to the client-side TJavascriptLogger.

getErrorTemplate (line 289)

Retrieves the template used for displaying external exceptions.

External exceptions are those displayed to end-users. They do not contain error source code. Therefore, you might want to override this method to provide your own error template for displaying certain external exceptions. The following tokens in the template will be replaced with corresponding content: %%StatusCode%% : the status code of the exception %%ErrorMessage%% : the error message (HTML encoded). %%ServerAdmin%% : the server admin information (retrieved from Web server configuration) %%Version%% : the version information of the Web server. %%Time%% : the time the exception occurs at

- return: the template content
- access: protected

string getErrorTemplate (integer $statusCode, Exception $exception)

- integer $statusCode: status code (such as 404, 500, etc.)
- Exception $exception: the exception to be displayed

getErrorTemplatePath (line 87)

- return: the directory containing error template files.
- access: public

string getErrorTemplatePath ()
getExceptionTemplate (line 262)

Retrieves the template used for displaying internal exceptions.

Internal exceptions will be displayed with source code causing the exception. This occurs when the application is in debug mode.

- return: the template content
- access: protected

string getExceptionTemplate (Exception $exception)

- Exception $exception: the exception to be displayed

handleError (line 115)

Handles PHP user errors and exceptions.

This is the event handler responding to the Error event raised in TApplication. The method mainly uses appropriate template to display the error/exception. It terminates the application immediately after the error is displayed.

- access: public

void handleError (mixed $sender, mixed $param)

- mixed $sender: sender of the event
- mixed $param: event parameter (if the event is raised by TApplication, it refers to the exception instance)

handleExternalError (line 149)

Displays error to the client user.

THttpException and errors happened when the application is in Debug mode will be displayed to the client user.

- access: protected

void handleExternalError (integer $statusCode, Exception $exception)

- integer $statusCode: response status code
- Exception $exception: exception instance

handleRecursiveError (line 179)

Handles error occurs during error handling (called recursive error).

THttpException and errors happened when the application is in Debug mode will be displayed to the client user. Error is displayed without using existing template to prevent further errors.

- access: protected

void handleRecursiveError (Exception $exception)

- Exception $exception: exception instance

init (line 77)

Initializes the module.

This method is required by IModule and is invoked by application.

- access: public

void init (TXmlElement $config)

- TXmlElement $config: module configuration

Redefinition of:

TModule::init()
  Initializes the module.

setErrorTemplatePath (line 98)

Sets the path storing all error and exception template files.

The path must be in namespace format, such as System.Exceptions (which is the default).

- access: public
- throws: TConfigurationException if the template path is invalid

void setErrorTemplatePath (string $value)

- string $value: template path in namespace format

#### Inherited Methods

Inherited From TModule

> TModule::getID()
> TModule::init()
> TModule::setID()

Inherited From TApplicationComponent

> TApplicationComponent::getApplication()
> TApplicationComponent::getRequest()
> TApplicationComponent::getResponse()
> TApplicationComponent::getService()
> TApplicationComponent::getSession()
> TApplicationComponent::getUser()
> TApplicationComponent::publishAsset()
> TApplicationComponent::publishFilePath()

Inherited From TComponent

> TComponent::addParsedObject()
> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::createdOnTemplate()
> TComponent::detachEventHandler()
> TComponent::evaluateExpression()
> TComponent::evaluateStatements()
> TComponent::getEventHandlers()
> TComponent::getSubProperty()
> TComponent::hasEvent()
> TComponent::hasEventHandler()
> TComponent::hasProperty()
> TComponent::raiseEvent()
> TComponent::setSubProperty()
> TComponent::__get()
> TComponent::__set()

Class Constants
ERROR_FILE_NAME = 'error' (line 57)

error template file basename

EXCEPTION_FILE_NAME = 'exception' (line 61)

exception template file basename

SOURCE_LINES = 12 (line 65)

number of lines before and after the error line to be displayed in case of an exception

Documentation generated on Mon, 21 Apr 2008 11:34:59 -0400 by phpDocumentor 1.3.0RC4