简体   繁体   中英

Tuning PHP exception reporting similar to error reporting

For Apache web server, we can tune the error reporting via error_reporting entry in php.ini .

Is there a similar setting for exception reporting?

My below code show that error_reporting doesn't effect exception throw command.

function actionTestThrow() {
    error_reporting(null);
    $i=122;        
    throw new Exception('abb');
    $i=344;        
    echo $i;
}

Exceptions are always fatal. You can't just hide them. If you want to ignore an exception, you'll need to handle it in a try catch block.


What you can do, is extend the exception class ( FatalException , NoticeException ) etc, and handle each differently, more on that on Extending Exceptions

我认为您应该使用try/catch块包装函数调用或函数体,当捕获到异常时,只需使用trigger_error函数即可通过php的error_reporting机制移动错误

Here is how you can set custom exception handler

function exception($e) {
var_dump($e); 
}

set_exception_handler ( 'exception' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM