Why does `catch (Exception $e)` not handle this `ErrorException`?

只愿长相守 提交于 2019-12-06 17:15:00

问题


I get the ErrorException on the function call bellow. How can this be? Why is it not caught?

try {
    static::$function_name($url);
}
catch (Exception $e) {}

The underlying reason for the error is a file_put_contents call. I'm using the Laravel 4 framework, if it makes any difference.


回答1:


I suspect that you need to write this:

try {
    static::$function_name($url);
} catch (\Exception $e) {}

Note the \ in front of Exception.

When you have declared a namespace, you need to specify the root namespace in front of classes like Exception, otherwise the catch block here will be looking for \Your\Namespace\Exception, and not just \Exception



来源:https://stackoverflow.com/questions/15071191/why-does-catch-exception-e-not-handle-this-errorexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!