0

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?

1
  • why don't u just catch the exception and see where it really originates Commented Sep 14, 2014 at 13:00

2 Answers 2

1

Don't use the general Exception handler to handle other types of exceptions. Register your own.

App::error(function(ExampleNamespace\MsgException $exception, $code)
{
    dd($exception); // debugging
});

More read about App::error are available here.

Sign up to request clarification or add additional context in comments.

1 Comment

Tanks, but that's not addressing the problem (however I tried it this way but it's not working - ofcourse not)
1

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.