From 63b136a2c44e50f9da0d98ac1722c8536de740d5 Mon Sep 17 00:00:00 2001 From: Denis Sokolov Date: Thu, 14 Nov 2013 21:07:07 +0100 Subject: [PATCH] Fix #112: pass exception handling on fatal errors properly --- src/Whoops/Run.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Whoops/Run.php b/src/Whoops/Run.php index 8368d5e..0278e66 100644 --- a/src/Whoops/Run.php +++ b/src/Whoops/Run.php @@ -326,7 +326,13 @@ class Run return true; } } - throw new ErrorException($message, $level, 0, $file, $line); + + $exception = new ErrorException($message, $level, 0, $file, $line); + if ($this->canThrowExceptions) { + throw $exception; + } else { + $this->handleException($exception); + } } } @@ -335,6 +341,11 @@ class Run */ public function handleShutdown() { + // If we reached this step, we are in shutdown handler. + // An exception thrown in a shutdown handler will not be propagated + // to the exception handler. Pass that information along. + $this->canThrowExceptions = false; + $error = error_get_last(); if ($error && $this->isLevelFatal($error['type'])) { $this->handleError( @@ -346,6 +357,12 @@ class Run } } + /** + * In certain scenarios, like in shutdown handler, we can not throw exceptions + * @var boolean + */ + private $canThrowExceptions = true; + private static function isLevelFatal($level) { return in_array(