TracNav menu
Ignoring errors
patError allows you to ignore some errors based on the error code. In our FileReader example, this means, that we could easily ignore the notice triggered, when opening an empty file. All you need to do, is pass the error code to the addIgnore() method of the patErrorManager class:
patErrorManager::addIgnore(NOTICE_FILE_EMPTY);
patErrorManager::setErrorHandling(E_NOTICE, 'die');
$file = new FileReader('./empty.txt');
$file->open();
Even though the file is empty, the script will not be terminated.
If we do not want to ignore the error at a later point, we can use the removeIgnore() method:
patErrorManager::removeIgnore(NOTICE_FILE_EMPTY);
$file = new FileReader('./empty.txt');
$file->open();
This time, the notice will not be ignored and the script terminated, as we set the error handling to die.
There are two more methods related to ignoring errors:
- getIgnore() returns a list of all error codes, that are currently ignored
- clearIgnore() clears the list of ignored error codes.
If you want to ignore an error only once, you may expect the error instead of ignoring it.
