问题
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