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

后端 未结 1 1459
别那么骄傲
别那么骄傲 2021-02-18 15:54

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

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


        
1条回答
  •  终归单人心
    2021-02-18 16:41

    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

    0 讨论(0)
提交回复
热议问题