-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rethrowing exceptions from error handler #1807
Comments
I think we spoke about this in IRC right? But yeah, I just don't think that's how they're supposed to work. I'd just stick with overloading the |
Overloading try
{
$user = User::findOrFail($id);
}
catch (HTTPException $e)
{
// HTTP exception because a model instance couldn't be found? A bit odd.
} |
You should be catching try
{
$user = User::findOrFail($id);
}
catch (Illuminate\Database\Eloquent\ModelNotFoundException $e)
{
throw new Symfony\Component\HttpKernel\Exception\HttpException( ... );
} Now wouldn't this nice if it was a Repository? |
I am catching |
Consider your use case and the current implementation on https://github.com/laravel/framework/blob/master/src/Illuminate/Exception/Handler.php#L219-L263.
As you can see from above code, it wasn't design to work that way. |
Looking at that code, if I change line 252 to |
Yes but it not going to work consistently: class FooException extends \Exception {}
class FoobarException extends FooException {}
class AwesomenessException extends \Exception {}
App::error(function(FooException $exception)
{
throw new FoobarException;
});
App::error(function(FoobarException $exception)
{
throw new AwesomenessException;
});
Route::get('foo', function()
{
throw new FooException;
});
class FooException extends \Exception {}
class FoobarException extends \Exception {}
class AwesomenessException extends \Exception {}
App::error(function(FooException $exception)
{
throw new FoobarException;
});
App::error(function(FoobarException $exception)
{
throw new AwesomenessException;
});
Route::get('foo', function()
{
throw new FooException;
}); I would expect
This just the one I can think of, but re-running the exception handlers array can easily odd results unless we really know what we are doing. However being sad that, Laravel is easily extend to our need. The handler class can easily be replace and bind to the global |
I've put in pull request #1959 which handles this and |
I don't like what this opens up. We'll just have people complaining about WSODs because they forgot a handler, etc. |
I've got a couple of error handlers:
Using
MyModel::findOrFail($id)
can throw theModelNotFoundException
which I'm catching but usingApp::abort
or throwing a new exception from within the handler errors with an "Error in exception handler" error (from https://github.com/laravel/framework/blob/master/src/Illuminate/Exception/Handler.php#L318).Is it not possible to re-throw an error in this way?
I can work around it by overriding
findOrFail()
in a base Model but I was wondering if the above could or should work?The text was updated successfully, but these errors were encountered: