Exception slipping exception handler

為{幸葍}努か 提交于 2019-12-25 05:09:11

问题


I got the following exception in my page:

Fatal error: Call to a member function someFunction() on a
    non-object in seomfile.php on line 15

My code near line 15 is:

try
{
    return getObject()->someFunction(); // line 15
}
catch(Exception $e) { }

I know getObject() returns null, but why isn't the try block catching it?


回答1:


PHP mixes Exceptions and Errors. You could use set_error_handler() to throw an exception on error.




回答2:


You can try to use something like this:

try {
    $object = getObject();
    If (!is_object($object)) {
        throw new Exception();
    }

    return $object->someFunction();
catch (Exception $e) {
}



回答3:


Because it's not an exception, it's a standard old-fashioned error.



来源:https://stackoverflow.com/questions/7180263/exception-slipping-exception-handler

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