示例#1
0
 /**
  * Actually handle the exception.
  * @param $exception
  */
 private function processException($exception)
 {
     Tier::clearOutputBuffer();
     //TODO - we are now failing. Replace error handler with instant
     //shutdown handler.
     $fallBackHandler = ['Tier\\Tier', 'processException'];
     if (class_exists('\\Throwable') === true) {
         $fallBackHandler = ['Tier\\Tier', 'processThrowable'];
     }
     $handler = $this->exceptionResolver->getExceptionHandler($exception, $fallBackHandler);
     try {
         call_user_func($handler, $exception);
     } catch (\Exception $e) {
         Tier::clearOutputBuffer();
         // The exception handler function also threw? Just exit.
         //Fatal error shutdown
         echo $e->getMessage();
         exit(-1);
     } catch (\Throwable $e) {
         Tier::clearOutputBuffer();
         //Fatal error shutdown
         echo $e->getMessage();
         exit(-1);
     }
 }
 public function testExceptionResolver()
 {
     $exceptionResolver = new ExceptionResolver();
     $fn = function () {
         return "Foo handler";
     };
     $defaultHandler = function () {
         return "Default handler";
     };
     $exceptionResolver->addExceptionHandler('FooException', $fn, 10);
     $exceptionResolver->addExceptionHandler('Fixtures\\FooException', $fn, ExceptionResolver::ORDER_LAST);
     $fooException = new FooException();
     $handler = $exceptionResolver->getExceptionHandler($fooException, $defaultHandler);
     $this->assertEquals("Foo handler", $handler());
     $barException = new BarException();
     $handler = $exceptionResolver->getExceptionHandler($barException, $defaultHandler);
     $this->assertEquals("Default handler", $handler());
 }
示例#3
0
文件: TierHTTPApp.php 项目: Zvax/Tier
 /**
  * @param Request $request
  */
 public function execute(Request $request)
 {
     try {
         $this->injector->alias('Room11\\HTTP\\Request', get_class($request));
         $this->injector->share($request);
         $this->executeInternal();
     } catch (\Exception $e) {
         list($handler, $exceptionClass) = $this->exceptionResolver->getExceptionHandler($e, 'processException');
         $injector = clone $this->injector;
         if (strcasecmp($exceptionClass, get_class($e)) !== 0) {
             $injector->alias($exceptionClass, get_class($e));
         }
         $injector->share($e);
         $injector->execute($handler);
     }
 }