PHP 7 try - catch: unable to catch “Catchable fatal error”

后端 未结 3 1576
青春惊慌失措
青春惊慌失措 2020-12-11 17:23

I am playing with try - catch block:



        
3条回答
  •  抹茶落季
    2020-12-11 18:28

    As user2782001 mentioned this is not a bug in the eyes of PHP dev's. They even noted that these type of errors should be referenced as 'recoverable':

    we should get rid of any references to "catchable" fatal errors (if they still exist) in favor of "recoverable" fatal errors. Using "catchable" here is confusing as they cannot be caught using catch blocks.

    On the ErrorException manual page there is a neat workaround converting those "catchable/recoverable" errors to ErrorException.

    
    

    now you will be able to catch those errors with:

    getMessage();
    }
    ?>
    

    or

    try {
        // Error code
    } catch (Throwable $t) { // this will catch both Errors and Exceptions
        echo $t->getMessage();
    }
    ?>
    

提交回复
热议问题