Code Issues – Catch block is empty
This code issue shows a warning when the catch block is empty. Usually empty catch block is a bad idea, because you are silently swallowing an error condition and then continuing an execution of the program, or the program may simply fail for an unknown reason.
In general, when an exception occurs, it can be thrown up to the caller, or it can be caught in a catch block. When catching an exception, it is recommended to inform the user about the problem, or log it for a future review.
Deciding what exactly to do depends on the nature of the problem. If there is an actual bug in the program, e.g. a defect that needs to be fixed, then one might do all of the possible solutions to let the user know about the problem and ask him to send some technical details to a program developer.
If the exception does not represent a bug, then different behavior may be appropriate. For example, if a problem with user input is detected and an exception is thrown as a result, then merely informing the user of the problem might be all that is required.
How to fix:
- Add the diagnostic message logging capability inside the catch block, e.g.,:
—– Products: CodeRush Pro Versions: 12.1 and up VS IDEs: any Updated: Nov/12/2012 ID: C067
- Code Issues – Try statement without catch or finally
- How to speed up the issue investigation time and help to eliminate complex problems
- Refactorings that work with strings – Use IsNullOrEmpty
- Refactoring using statements with CodeRush/Refactor!
- Code Issues of the dead code type for members and blocks