Error handling
The framework features the
errorHandler function, that is intended to do global
error handling. This function is used to catch and handle errors at a central place. For this
reason, it uses a
ErrorHandler component, that can be configured within the registry.
The error handler itself is then responsible for the handling of the current error.
The preconfigured APF error handler saves the error message into a log file and displays the nice
error screen including the stacktrace. Details can be taken from the
API documentation of the
DefaultErrorHandler class.
To replace the preconfigured
DefaultErrorHandler with an own class, the registry offset
ErrorHandler within the
apf::core namespace must be filled with the
desired
ErrorHandlerDefinition instance. The configuration of the error handling
component must be placed in the bootstrap file directly after the
pagecontroller.php is
included.
The definition of a custom error handler looks as follows:
PHP-Code
$reg = &Singleton::getInstance('Registry');
$reg->register(
'apf::core',
'ErrorHandler',
new ErrorHandlerDefinition(
'my::errorhandler::namespace',
'MyErrorHandler'
)
);
As you can take from the example, the desired
ErrorHandler is referenced by it's
namespace and it's class name.
Note: if the registry offset does not contain a valid definition, the errors are
displayed in text mode. You can identify the fallback mode by the prefix
APF-Template
APF catchable error:
In this cases, the definition or the implementation of the error handler class must be checked.
In order to deactivate the ErrorHandler, initilize the registry offset with
null.
To introduce a custom error handling, you must implement the
AbstractErrorHandler.
This class defines the following interface:
PHP-Code
class AbstractErrorHandler extends coreObject {
function handleError($errorNumber,$errorMessage,$errorFile,$errorLine){
}
}
If an error occures, the
handleError is applied the following parameters:
- error number
- error message
- filename where the error occures
- line where the error occures
Due to the fact, that the error handling is done in an page controller independent class, that is
not created by the service manager, the current
Context and the current
Language are
not available!
If these information are important for the error handling, the must be obtained from information
containers available within an application or module (e.g. application model class). The environment
param is available via the registry as mentioned in the corresponding documentation chapter.
The global error handling mechanism can be used by calling the PHP function
Details on the usage of the function can be taken from the online documentation under
http://php.net/trigger_error.
Comments
Do you want to add a comment to the article above, or do you want to post additional hints? So please click
here. Comments already posted can be found below.
There are no comments belonging to this article.