How to catch exceptions in your ZF2 controllers?

后端 未结 1 1220
小蘑菇
小蘑菇 2020-12-10 06:17

I\'ve setup the ZendSkeletonApplication with ZF 2.0.3 and I am unable to catch exceptions in my controllers. For instance if I put the below piece of code in

相关标签:
1条回答
  • 2020-12-10 07:14

    You are throwing PHP's generic Exception

    throw new \Exception("My exception");
    

    but you catch the Exception from the current namespace

    } catch (Exception $e) {
    

    Assuming your controller is in Application\Controller, you either have to declare

    use \Exception;
    

    above your class to import the global Exception into the current namespace or

    } catch (\Exception $e) {
    

    to catch PHP's global Exception.

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