Add better handling of ErrorException stack traces

This commit is contained in:
filp
2013-03-13 23:46:53 +00:00
parent 67e1e0d8a5
commit 89d59e8773
4 changed files with 28 additions and 5 deletions
+2 -1
View File
@@ -40,7 +40,8 @@ $run->pushHandler(function($exception, $inspector, $run) {
$run->register();
function fooBar() {
throw new Exception("Something broke!");
// throw new Exception("Something broke!");
file("FAIILL");
}
function bar()
+14
View File
@@ -0,0 +1,14 @@
<?php
/**
* Damnit - php errors for cool kids
* @author Filipe Dobreira <http://github.com/filp>
*/
namespace Damnit\Exception;
use ErrorException as BaseErrorException;
/**
* Wraps ErrorException; mostly used for typing (at least now)
* to easily cleanup the stack trace of redundant info.
*/
class ErrorException extends BaseErrorException {}
+11 -3
View File
@@ -6,6 +6,7 @@
namespace Damnit\Exception;
use Damnit\Exception\FrameIterator;
use Damnit\Exception\ErrorException;
use Exception;
class Inspector
@@ -53,9 +54,16 @@ class Inspector
{
if($this->framesIterator === null) {
$frames = $this->exception->getTrace();
$firstFrame = $this->getFrameFromException($this->exception);
array_unshift($frames, $firstFrame);
// If we're handling an ErrorException thrown by Damnit,
// get rid of the last, which matches the handleError method,
// and do not add the current exception to trace
if($this->exception instanceof ErrorException) {
array_shift($frames);
} else {
$firstFrame = $this->getFrameFromException($this->exception);
array_unshift($frames, $firstFrame);
}
$this->framesIterator = new FrameIterator($frames);
}
+1 -1
View File
@@ -9,8 +9,8 @@ use Damnit\Handler\HandlerInterface;
use Damnit\Handler\Handler;
use Damnit\Handler\CallbackHandler;
use Damnit\Exception\Inspector;
use Damnit\Exception\ErrorException;
use InvalidArgumentException;
use ErrorException;
use Exception;
class Run