Skip to content
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

[6.x] Pass the exception to the rescue closure #30838

Merged
merged 1 commit into from Dec 16, 2019
Merged

Conversation

@SjorsO
Copy link
Contributor

SjorsO commented Dec 14, 2019

I'm using the rescue helper to make sure a fragile part of my application can't cause a crash. I'm storing both the error message and the object to make debugging easier. The problem is that when using the rescue helper, i can only see the real exception in my logs, and i can't store it in the database.

Currently:

[$error, $object] = rescue(function () use ($file) {
    return [null, new SomeFragileObject($file)];
}, ['An exception was thrown', null]);

With this PR i can do this:

[$error, $object] = rescue(function () use ($file) {
    return [null, new SomeFragileObject($file)];
}, function ($e) {
    // $e can be a custom exception with a detailed error message
    return [$e->getMessage(), null];
});
@taylorotwell taylorotwell merged commit db794ce into laravel:6.x Dec 16, 2019
2 checks passed
2 checks passed
continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.