lanmind
lanmind

Reputation: 119

PHP's error levels

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

Answers (4)

Matthew
Matthew

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.

Ref

You cannot handle the following other error types for similar reasons:

  • E_PARSE
  • E_CORE_ERROR
  • E_CORE_WARNING
  • E_COMPILE_ERROR
  • E_COMPILE_WARNING

set_error_handler() however can handle the follow errors:

Upvotes: 8

James
James

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

gnarf
gnarf

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

Ólafur Waage
Ólafur Waage

Reputation: 70001

You can create your own error handling and halt the script and actually do anything you want when an error occurs.

set_error_handler()

Upvotes: 2

Related Questions