Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 337
duality_ Avatar asked Feb 25 '13 16:02

duality_


1 Answers

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

like image 59
pete otaqui Avatar answered Oct 23 '22 05:10

pete otaqui