TracNav menu
Custom error levels
By default, patError enables to to use three different error levels that match the typical PHP error levels:
- errors (E_ERROR)
- warnings (E_WARNING)
- notices (E_NOTICE)
However, it is also possible to register more error levels with the patErrorManager class and use them in the setErrorHandling() and raise() methods. All you need to do is use the registerErrorLevel() method and pass two parameters:
- integer value representing the level
- human readable description of the level
The integer level of the error level should either be any of the constants defined by PHP or a value higher than 4096, so it does not conflict with the PHP error constants.
At first, let us take a look that imports the E_STRICT level into patErrorManager:
<?php // register the level patErrorManager::registerErrorLevel(E_STRICT, 'Strict standards'); // set the error handling patErrorManager::setErrorHandling(E_STRICT, 'verbose'); // trigger an error patErrorManager::raise(E_STRICT, $errorCode, 'You did not follow strict standards.'); ?>
The second example defines a complety new error level:
<?php
define('ERROR_LEVEL_INFO', 8192);
// register the level
patErrorManager::registerErrorLevel(EEROR_LEVEL_INFO, 'Info');
// set the error handling
patErrorManager::setErrorHandling(ERROR_LEVEL_INFO, 'echo');
// trigger an error
patErrorManager::raise(ERROR_LEVEL_INFO, $errorCode, 'This is just for your information.');
?>
You can use as many different error levels as you like in your applications. If you distribute them, you should document the different levels that your applications uses.
