@@ -117,8 +117,15 @@ public function run(InputInterface $input = null, OutputInterface $output = null
117
117
$ this ->configureIO ($ input , $ output );
118
118
119
119
try {
120
+ $ e = null ;
120
121
$ exitCode = $ this ->doRun ($ input , $ output );
121
- } catch (\Exception $ e ) {
122
+ } catch (\Exception $ x ) {
123
+ $ e = $ x ;
124
+ } catch (\Throwable $ x ) {
125
+ $ e = new FatalThrowableError ($ x );
126
+ }
127
+
128
+ if (null !== $ e ) {
122
129
if (!$ this ->catchExceptions ) {
123
130
throw $ e ;
124
131
}
@@ -839,47 +846,43 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
839
846
}
840
847
841
848
if (null === $ this ->dispatcher ) {
842
- try {
843
- return $ command ->run ($ input , $ output );
844
- } catch (\Exception $ e ) {
845
- throw $ e ;
846
- } catch (\Throwable $ e ) {
847
- throw new FatalThrowableError ($ e );
848
- }
849
+ return $ command ->run ($ input , $ output );
849
850
}
850
851
851
852
$ event = new ConsoleCommandEvent ($ command , $ input , $ output );
852
- $ this -> dispatcher -> dispatch (ConsoleEvents:: COMMAND , $ event ) ;
853
+ $ e = null ;
853
854
854
- if ($ event ->commandShouldRun ()) {
855
- try {
856
- $ e = null ;
855
+ try {
856
+ $ this ->dispatcher ->dispatch (ConsoleEvents::COMMAND , $ event );
857
+
858
+ if ($ event ->commandShouldRun ()) {
857
859
$ exitCode = $ command ->run ($ input , $ output );
858
- } catch (\Exception $ x ) {
859
- $ e = $ x ;
860
- } catch (\Throwable $ x ) {
861
- $ e = new FatalThrowableError ($ x );
860
+ } else {
861
+ $ exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED ;
862
862
}
863
- if (null !== $ e ) {
864
- $ event = new ConsoleExceptionEvent ($ command , $ input , $ output , $ e , $ e ->getCode ());
865
- $ this ->dispatcher ->dispatch (ConsoleEvents::EXCEPTION , $ event );
866
-
867
- if ($ e !== $ event ->getException ()) {
868
- $ x = $ e = $ event ->getException ();
869
- }
863
+ } catch (\Exception $ x ) {
864
+ $ e = $ x ;
865
+ } catch (\Throwable $ x ) {
866
+ $ e = new FatalThrowableError ($ x );
867
+ }
870
868
871
- $ event = new ConsoleTerminateEvent ($ command , $ input , $ output , $ e ->getCode ());
872
- $ this ->dispatcher ->dispatch (ConsoleEvents::TERMINATE , $ event );
869
+ if (null !== $ e ) {
870
+ $ event = new ConsoleExceptionEvent ($ command , $ input , $ output , $ e , $ e ->getCode ());
871
+ $ this ->dispatcher ->dispatch (ConsoleEvents::EXCEPTION , $ event );
873
872
874
- throw $ x ;
873
+ if ($ e !== $ event ->getException ()) {
874
+ $ x = $ e = $ event ->getException ();
875
875
}
876
- } else {
877
- $ exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED ;
876
+ $ exitCode = $ e ->getCode ();
878
877
}
879
878
880
879
$ event = new ConsoleTerminateEvent ($ command , $ input , $ output , $ exitCode );
881
880
$ this ->dispatcher ->dispatch (ConsoleEvents::TERMINATE , $ event );
882
881
882
+ if (null !== $ e ) {
883
+ throw $ x ;
884
+ }
885
+
883
886
return $ event ->getExitCode ();
884
887
}
885
888
0 commit comments