php: try-catch not catching all exceptions

后端 未结 4 1036
-上瘾入骨i
-上瘾入骨i 2020-12-23 17:34

I\'m trying to do the following:

try {
    // just an example
    $time      = \'wrong datatype\';
    $timestamp = date(\"Y-m-d H:i:s\", $time);
} catch (Ex         


        
4条回答
  •  时光取名叫无心
    2020-12-23 17:56

    The shorter that I have found:

    set_error_handler(function($errno, $errstr, $errfile, $errline ){
        throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
    });
    

    Makes all errors becoming instance of catchable ErrorException

提交回复
热议问题