Reputation: 119
The only error level in PHP that will halt the script but can be caught and dealt with have to be triggered with the trigger_error() function correct? I'm referring to the "E_USER_ERROR" error level. The "E_ERROR" error will simply halt the script and I can't do anything about it as the developer.
Upvotes: 5
Views: 4289
Reputation: 3106
E_ERROR will simply stop the script. It's meant to be used for:
Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.
You cannot handle the following other error types for similar reasons:
set_error_handler() however can handle the follow errors:
Upvotes: 8
Reputation: 3275
You can catch E_ERROR using a shutdown script
from my posting http://jarofgreen.wordpress.com/2011/02/04/catching-php-errors/
register_shutdown_function(‘x’);
function x() {
$error = error_get_last();
if ($error) {
// deal with $error['file'],$error['line'],$error['message'],$error['type']
}
}
Upvotes: 3
Reputation: 106392
Not really sure what your driving at or trying to do here, but if you're looking for a way to "catch" and deal with 'errors' - Maybe look into exceptions.
From PHP Manual on Exceptions
An exception can be thrown, and caught ("catched") within PHP. Code may be surrounded in a try block, to facilitate the catching of potential exceptions. Each try must have at least one corresponding catch block. Multiple catch blocks can be used to catch different classes of exeptions. Normal execution (when no exception is thrown within the try block, or when a catch matching the thrown exception's class is not present) will continue after that last catch block defined in sequence. Exceptions can be thrown (or re-thrown) within a catch block.
Upvotes: 1
Reputation: 70001
You can create your own error handling and halt the script and actually do anything you want when an error occurs.
Upvotes: 2