@@ -38,7 +38,7 @@ abstract class AbstractApp
3838 */
3939 protected $ config = [
4040 'env ' => 'pdt ' , // dev test pdt
41- 'debug ' => false ,
41+ 'debug ' => true ,
4242 'name ' => 'My Console ' ,
4343 'version ' => '0.5.1 ' ,
4444 'publishAt ' => '2017.03.24 ' ,
@@ -118,7 +118,7 @@ public function run($exit = true)
118118 // do run ...
119119 try {
120120 $ returnCode = $ this ->dispatch ($ command );
121- } catch (\Exception $ e ) {
121+ } catch (\Throwable $ e ) {
122122 self ::fire (self ::ON_RUN_ERROR , [$ e , $ this ]);
123123 $ returnCode = $ e ->getCode () === 0 ? __LINE__ : $ e ->getCode ();
124124 $ this ->dispatchExHandler ($ e );
@@ -243,7 +243,11 @@ public function command(string $name, $handler = null)
243243 public function commands (array $ commands )
244244 {
245245 foreach ($ commands as $ name => $ handler ) {
246- $ this ->command ($ name , $ handler );
246+ if (is_int ($ name )) {
247+ $ this ->command ($ handler );
248+ } else {
249+ $ this ->command ($ name , $ handler );
250+ }
247251 }
248252 }
249253
@@ -253,20 +257,30 @@ public function commands(array $commands)
253257
254258 /**
255259 * 运行异常处理
256- * @param \Exception $e
260+ * @param \Exception|\Throwable $e
257261 * @throws \Exception
258262 */
259- protected function dispatchExHandler (\ Exception $ e )
263+ protected function dispatchExHandler ($ e )
260264 {
261265 // $this->logger->ex($e);
262266
263267 // open debug, throw exception
264268 if ($ this ->isDebug ()) {
265- throw $ e ;
269+ $ message = sprintf (
270+ "<bold>Exception(%d)</bold>: <red>%s</red> \nCalled At %s, Line: <cyan>%d</cyan> \nCatch the exception by: %s \nCode Trace: \n%s \n" ,
271+ $ e ->getCode (),
272+ $ e ->getMessage (),
273+ $ e ->getFile (),
274+ $ e ->getLine (),
275+ get_class ($ e ),
276+ $ e ->getTraceAsString ()
277+ );
278+
279+ $ this ->output ->write ($ message , false );
280+ } else {
281+ // simple output
282+ $ this ->output ->error ('An error occurred! MESSAGE: ' . $ e ->getMessage ());
266283 }
267-
268- // no output
269- $ this ->output ->error ('An error occurred! MESSAGE: ' . $ e ->getMessage ());
270284 }
271285
272286 /**
0 commit comments