@@ -98,7 +98,10 @@ public function onDispatch(MvcEvent $e)
9898 } catch (InvalidServiceException $ exception ) {
9999 $ return = $ this ->marshalControllerNotFoundEvent ($ application ::ERROR_CONTROLLER_INVALID , $ controllerName , $ e , $ application , $ exception );
100100 return $ this ->complete ($ return , $ e );
101- } catch (\Exception $ exception ) {
101+ } catch (\Throwable $ exception ) {
102+ $ return = $ this ->marshalBadControllerEvent ($ controllerName , $ e , $ application , $ exception );
103+ return $ this ->complete ($ return , $ e );
104+ } catch (\Exception $ exception ) { // @TODO clean up once PHP 7 requirement is enforced
102105 $ return = $ this ->marshalBadControllerEvent ($ controllerName , $ e , $ application , $ exception );
103106 return $ this ->complete ($ return , $ e );
104107 }
@@ -109,15 +112,22 @@ public function onDispatch(MvcEvent $e)
109112
110113 $ request = $ e ->getRequest ();
111114 $ response = $ application ->getResponse ();
115+ $ caughtException = null ;
112116
113117 try {
114118 $ return = $ controller ->dispatch ($ request , $ response );
115- } catch (\Exception $ ex ) {
119+ } catch (\Throwable $ ex ) {
120+ $ caughtException = $ ex ;
121+ } catch (\Exception $ ex ) { // @TODO clean up once PHP 7 requirement is enforced
122+ $ caughtException = $ ex ;
123+ }
124+
125+ if ($ caughtException !== null ) {
116126 $ e ->setName (MvcEvent::EVENT_DISPATCH_ERROR );
117127 $ e ->setError ($ application ::ERROR_EXCEPTION );
118128 $ e ->setController ($ controllerName );
119129 $ e ->setControllerClass (get_class ($ controller ));
120- $ e ->setParam ('exception ' , $ ex );
130+ $ e ->setParam ('exception ' , $ caughtException );
121131
122132 $ return = $ application ->getEventManager ()->triggerEvent ($ e )->last ();
123133 if (! $ return ) {
@@ -135,7 +145,7 @@ public function reportMonitorEvent(MvcEvent $e)
135145 {
136146 $ error = $ e ->getError ();
137147 $ exception = $ e ->getParam ('exception ' );
138- if ($ exception instanceof \Exception) {
148+ if ($ exception instanceof \Exception || $ exception instanceof \Throwable ) { // @TODO clean up once PHP 7 requirement is enforced
139149 zend_monitor_custom_event_ex ($ error , $ exception ->getMessage (), 'Zend Framework Exception ' , ['code ' => $ exception ->getCode (), 'trace ' => $ exception ->getTraceAsString ()]);
140150 }
141151 }
0 commit comments