TracNav menu
Expecting errors
In some cases you might expect a special error to occur and might favour to ignore the error in this case. That's why patErrorManager provides the pushExpect() and popExpect() methods. The first one can be used to ignore one or several errors, while the latter removes these error codes from the list of temporary ignored codes.
This is best illustrated using an example:
<?php
// ignore the ERROR_NOT_AUTHENTICATED error
patErrorManager::pushExpect(array(ERROR_NOT_AUTHENTICATED));
$user = Auth::getCurrentUser();
// Now also ignore ERROR_FILE_NOT_FOUND and ERROR_FILE_NOT_READABLE
patErrorManager::pushExpect(array(ERROR_FILE_NOT_FOUND, ERROR_FILE_NOT_READABLE));
$file = new FileReader('foo.txt');
$file->open();
$file->close();
// No longer ignore ERROR_FILE_NOT_FOUND and ERROR_FILE_NOT_READABLE
// ERROR_NOT_AUTHENTICATED is still ignored
patErrorManager::popExpect();
$user->logout();
// Now stop ignoring ERROR_NOT_AUTHENTICATED
patErrorManager::popExpect();
?>
Using these two methods, you temporarily ignore groups of errors in parts of your application. If you want to ignore an error code in all parts of the applisation, we recommend you to use the ignoreError() method instead.
To stop expecting any errors, just call the patErrorManager::clearExpect() method.
