-
-
Notifications
You must be signed in to change notification settings - Fork 783
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
Incorrect (or unclear) EmptyCatchBlock rule #2602
Comments
This rule works as intended. If you don't care about the exceptions you should rename the exception to
Or if you don't care about empty catch bloks you can disable the rule. |
To be clear, the rule
... should thus be interpreted as empty catch blocks are a bad idea. My point was if that is the case this is unclear documentation. As in, they do serve a purpose: they make sure the code compiles! And,
... should be interpreted as, it is our recommendation you remove the empty class block, but classes without class blocks are perfectly fine. Seems like spurious copy/pasting to me with unintended consequences. Either way, yes, I disabled it. |
You are completely right! Could you create a PR fixing the documentation? Thanks for insist, I misunderstood the issue. |
Can do, and less-ambiguous documentation will definitely improve it. But the question whether or not this should be part of the 'empty block' rule set remains. |
I think that it should remain there. The problem is still the same: An empty block is a smell code. The only difference is that here we can't remove it. We should use it or, if we REALLY want to ignore it, add the exception a name that reflects that we really don't care about it. |
Expected Behavior
I expected the
EmptyCatchBlock
rule to behave similarly to some of the other empty block rules. For example, theEmptyClassBlock
rule recommends that empty class blocks should be removed.But, in the case of catch blocks, removing the block results in the compilation error "Expecting a block { ... }". Therefore, either the intent behind this recommendation does not make sense (removing the block), or it is poorly documented. One could argue empty catch blocks are a bad idea since it indicates the exception hasn't been handled, but this is not what is conveyed by the rule, documentation, and recommendation. This rule thus does not seem on a par with the other empty block rules.
Observed Behavior
Using the default detekt configuration, non-compilable code passes and compilable code does not pass the test:
Steps to Reproduce
Context
In the above code sample, I find the cleanest way to set 'success' to true to place it within the
try
block. Alternatives involve more boolean flipping, before, after, or in the catch blocks.Your Environment
The text was updated successfully, but these errors were encountered: