Stricter version of EmptyCatchBlock? #3095
maikelsteneker
started this conversation in
Ideas
Replies: 1 comment 4 replies
-
Isn't UnusedLocalVariable exactly that? It isn't specific to catch blocks, but, it doesn't need to be. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
PMD includes the rule EmptyCatchBlock that flags empty catch blocks. The idea behind this is that exceptions shouldn't be ignored, but should be acted on or reported.
Now consider code such as the following:
In this case, the code can probably be improved by catching a more specific error than the generic
Exception
, but in addition to this, it would probably be useful to keep the message or stacktrace for logging purposes. I would formalize this to: the exception variable should be referred to somewhere in the catch block. This could be a separate rule, or it could be an addition to an existing PMD rule.Any thoughts on this? Should I create an issue for this?
Beta Was this translation helpful? Give feedback.
All reactions