简体   繁体   English

无法捕获Symfony 3.4中的异常

[英]Unable to Catch Exceptions in Symfony 3.4

I am using symfony 3.4. 我正在使用symfony 3.4。 I am not able to catch the Exception. 我无法捕捉到异常。 Please help me out. 请帮帮我。

try{
        $a= 5/0;
}catch (\Exception $e){
        print_r('Exception Caught...');
}

error messsage: The server returned a 错误消息:服务器返回了

500 Internal Server Error 500内部服务器错误

Division by zero is a Fatal Error, not an exception that can be caught. 除以零是致命错误,不是可以捕获的异常。 You could however use the set_error_handler function to create an error handler that throws an exception instead: 但是,您可以使用set_error_handler函数来创建引发异常的错误处理程序:

Place the following code anywhere before your error causing code: 将以下代码放在导致错误的代码之前的任何位置:

set_error_handler(function ($errno, $errstr) {
    throw new \Exception('Fatal Error: '.$errstr);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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