-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[SR-978] Warn on do {} with only one empty catch {} block #43590
Comments
How do you silence the warning? |
Morally, if you don't expect any errors to happen, you should use |
Yes, but what about "I want to catch this particular error, but ignore any others?" ("I want to ignore this particular error" is easy enough to special-case.) |
I see what you're saying. IMO, if you do that, we should let it pass: do {
try something()
} catch Foo.Error {
handleFooError()
} catch {
/* do nothing */
} IMO, it's only the case where you do nothing more than do { ... } catch {} that deserves a warning. |
Comment by Josef Willsher (JIRA) I’m happy to implement this. How should we handle cases where the do block contains more than 1 expression—we can't issue a fixit here, but should I still emit a warning? |
If the do block contains multiple statements, you should still be able to change every |
Comment by Josef Willsher (JIRA)
Are you sure its not too much compiler gymnastics for a fixit to change a whole scope's I already have it emitting a warning for a single, empty, unguarded catch block, and I’m happy to implement the fixit either way. |
Sure, it might be reasonable to just warn without fixits if the `do` block is too complex. |
Resetting assignee for all Starter Bugs not modified since 2018. |
Additional Detail from JIRA
md5: d5f41243d2aaf067f1ecd57198c44970
Issue Description:
Eric Knapp caught some sample code in the wild unwisely using an empty catch block to swallow errors:
https://twitter.com/ejknapp/status/710589235464523776
We should warn on this to encourage people to use
try!
to trap on unexpected errors instead.The text was updated successfully, but these errors were encountered: