PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class TErrorHandler

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 setErrorTemplatePath 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" />

TComponent
Extended by TApplicationComponent
Extended by TModule implements IModule
Extended by TErrorHandler

Direct known subclasses

TCallbackErrorHandler
Package: System\Exceptions
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Exceptions/TErrorHandler.php
Methods summary
public
# init( TXmlElement $config )

Initializes the module. This method is required by IModule and is invoked by application.

Initializes the module. This method is required by IModule and is invoked by application.

Parameters

$config
TXmlElement
module configuration

Overrides

TModule::init()
public string
# getErrorTemplatePath( )

Returns

string
the directory containing error template files.
public
# setErrorTemplatePath( string $value )

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).

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).

Parameters

$value
string
template path in namespace format

Throws

TConfigurationException
if the template path is invalid
public
# handleError( mixed $sender, mixed $param )

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.

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.

Parameters

$sender
mixed
sender of the event
$param
mixed
event parameter (if the event is raised by TApplication, it refers to the exception instance)
protected static string
# hideSecurityRelated( string $value, Exception|null$exception $exception = null )

Parameters

$value
string
$value
$exception
Exception|null$exception
$exception

Returns

string

Since

3.1.6
protected
# handleExternalError( integer $statusCode, Exception $exception )

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

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

Parameters

$statusCode
integer
response status code
$exception
Exception
exception instance
protected
# handleRecursiveError( Exception $exception )

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.

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.

Parameters

$exception
Exception
exception instance
protected
# displayException( Exception $exception )

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.

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.

Parameters

$exception
Exception
exception instance
protected string
# getExceptionTemplate( Exception $exception )

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.

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.

Parameters

$exception
Exception
the exception to be displayed

Returns

string
the template content
protected string
# getErrorTemplate( integer $statusCode, Exception $exception )

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

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

Parameters

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

Returns

string
the template content
Methods inherited from TModule
getID(), setID()
Methods inherited from TApplicationComponent
getApplication(), getRequest(), getResponse(), getService(), getSession(), getUser(), publishAsset(), publishFilePath()
Methods inherited from TComponent
__call(), __construct(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants summary
string ERROR_FILE_NAME 'error'
#

error template file basename

error template file basename

string EXCEPTION_FILE_NAME 'exception'
#

exception template file basename

exception template file basename

integer SOURCE_LINES 12
#

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

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

Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO