Reputation: 451
I use a single Closure to handle exceptions in my app:
App::error(function(Exception $exception, $code)
{
if (is_a($exception, 'MsgException')) {
...
return;
}
dd($exception); // debugging
});
The strange thing is that if I throw a MsgException
...
<?php use MsgException; // alias for ExampleNamespace\MsgException
...
throw new MsgException();
...which is a custom class...
<?php namespace ExampleNamespace;
use RuntimeException;
class MsgException extends RuntimeException {}
... is_a($exception)
is false
and dd($exception)
says it's an ErrorException
.
I have no idea why this is happening. Any suggestions or ideas how I can debug my application?
Upvotes: 0
Views: 1417
Reputation: 451
Well the short answer is pretty simple: It's not working because the exception is thrown inside of a view. You can test this by simple adding
throw new \RuntimeException('Test');
to a controller method or a routing closure or any place outside a view and by adding
<?php throw new \RuntimeException('Test'); ?>
to a view template. Laravel will show the first one as a RuntimeException
and the second as an ErrorException
.
Unfortunately this isn't helping to actually solve the problem.
PS: In Illuminate\View\Engines\CompilerEngine the handleViewException method replaces the original exception:
protected function handleViewException($e, $obLevel)
{
$e = new \ErrorException($this->getMessage($e), 0, 1, $e->getFile(), $e->getLine(), $e);
parent::handleViewException($e, $obLevel);
}
Upvotes: 1