Add Fatal Error handling

This commit is contained in:
filp
2013-03-13 14:21:08 +00:00
parent 6e59e67111
commit e6005b717b
2 changed files with 34 additions and 10 deletions
+13 -10
View File
@@ -228,17 +228,20 @@
<div class="details-container cf">
<div class="frame-code-container <?php echo (!$v->hasFrames ? 'empty' : '') ?>">
<?php foreach($v->frames as $i => $frame): ?>
<div class="frame-code <?php echo ($i == 0 ) ? 'active' : '' ?>" id="frame-code-<?php echo $i ?>">
<?php
$line = $frame->getLine();
// the $line is 1-indexed, we nab -1 where needed to account for this
$range = $frame->getFileLines($line - 3, 4);
$start = key($range) + 1;
$code = join("\n", $range);
?>
<pre class="code-block prettyprint linenums:<?php echo $start ?>"><?php echo $e($code) ?></pre>
</div>
<?php $line = $frame->getLine(); ?>
<?php if($line !== null): ?>
<div class="frame-code <?php echo ($i == 0 ) ? 'active' : '' ?>" id="frame-code-<?php echo $i ?>">
<?php
// the $line is 1-indexed, we nab -1 where needed to account for this
$range = $frame->getFileLines($line - 3, 4);
$start = key($range) + 1;
$code = join("\n", $range);
?>
<pre class="code-block prettyprint linenums:<?php echo $start ?>"><?php echo $e($code) ?></pre>
</div>
<?php endif ?>
<?php endforeach ?>
</div>
+21
View File
@@ -16,6 +16,7 @@ class Run
{
const EXCEPTION_HANDLER = 'handleException';
const ERROR_HANDLER = 'handleError';
const SHUTDOWN_HANDLER = 'handleShutdown';
protected $isRegistered;
@@ -75,6 +76,7 @@ class Run
if(!$this->isRegistered) {
set_error_handler(array($this, self::ERROR_HANDLER));
set_exception_handler(array($this, self::EXCEPTION_HANDLER));
register_shutdown_function(array($this, self::SHUTDOWN_HANDLER));
$this->isRegistered = true;
}
@@ -123,6 +125,10 @@ class Run
break;
}
}
// And we're done!
$this->unregister();
exit;
}
/**
@@ -146,6 +152,21 @@ class Run
);
}
/**
* Special case to deal with Fatal errors and the like.
*/
public function handleShutdown()
{
if($this->isRegistered && $error = error_get_last()) {
$this->handleError(
$error['type'],
$error['message'],
$error['file'],
$error['line']
);
}
}
/**
* @param Exception $exception
* @return Damnit\Exception\Inspector