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

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

merged 1 commit into from
Dec 16, 2019

Conversation

SjorsO
Copy link
Contributor

@SjorsO 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants