@@ -117,10 +117,17 @@ 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
- throw $ e ;
130
+ throw $ x ;
124
131
}
125
132
126
133
if ($ output instanceof ConsoleOutputInterface) {
@@ -839,47 +846,42 @@ 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
- }
870
-
871
- $ event = new ConsoleTerminateEvent ($ command , $ input , $ output , $ e ->getCode ());
872
- $ this ->dispatcher ->dispatch (ConsoleEvents::TERMINATE , $ event );
863
+ } catch (\Exception $ x ) {
864
+ $ e = $ x ;
865
+ } catch (\Throwable $ x ) {
866
+ $ e = new FatalThrowableError ($ x );
867
+ }
868
+ if (null !== $ e ) {
869
+ $ event = new ConsoleExceptionEvent ($ command , $ input , $ output , $ e , $ e ->getCode ());
870
+ $ this ->dispatcher ->dispatch (ConsoleEvents::EXCEPTION , $ event );
873
871
874
- throw $ x ;
872
+ if ($ e !== $ event ->getException ()) {
873
+ $ x = $ e = $ event ->getException ();
875
874
}
876
- } else {
877
- $ exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED ;
875
+ $ exitCode = $ e ->getCode ();
878
876
}
879
877
880
878
$ event = new ConsoleTerminateEvent ($ command , $ input , $ output , $ exitCode );
881
879
$ this ->dispatcher ->dispatch (ConsoleEvents::TERMINATE , $ event );
882
880
881
+ if (null !== $ e ) {
882
+ throw $ x ;
883
+ }
884
+
883
885
return $ event ->getExitCode ();
884
886
}
885
887
0 commit comments