PHP'nin hata seviyeleri

4 Cevap

Sadece error level in PHP Bu komut durur ama yakalandı ve doğru trigger_error () fonksiyonu ile tetiklenen olması ile ele alınabilir? Ben "E_USER_ERROR" hata seviyesine bahsediyorum. "E_ERROR" hata sadece komut durur ve ben geliştirici olarak bu konuda bir şey yapamaz.

4 Cevap

E_ERROR sadece komut duracaktır. Bunun için kullanılacak olması gerektiği:

Ölümcül çalışma zamanı hataları. Bunlar bir bellek ayırma sorunu olarak kurtarıldı edilemez hataları gösterir. Script yürütme durdurulur.

Ref

Siz benzer nedenlerle aşağıdaki diğer hata türleri işleyemez:

  • E_PARSE
  • E_CORE_ERROR
  • E_CORE_warning
  • E_COMPILE_ERROR
  • E_COMPILE_warning

set_error_handler() ancak takip hataları işleyebilir:

Sen bir kapatma komut dosyası kullanarak E_ERROR yakalayabilirsiniz

Benim ilanıyla 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']
}
}

Kendi hata işleme oluşturmak ve komut durdurmak ve aslında bir hata oluştuğunda istediğiniz her şeyi yapabilirsiniz.

set_error_handler()

Gerçekten emin değil ne sizin sürüş ya da burada yapmaya çalışıyor, ama sen "yakalamak" için bir yol arıyor ve 'hataları' ile uğraşmak eğer - Belki içine bakmak 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.