Synopsis: | Do not silently ignore exceptions |
Language: | C# |
Severity Level: | 1 |
Category: | Exceptions |
Description: |
An empty catch block for all exceptions makes it really hard to find problems. The catch block should at least contain one of the following items:
Examples: try { ... } catch (Exception) // <-- Violation 8@110 { // Nothing is done here, so we silently ignore the exception } try { ... } catch (Exception) // <-- Violation 8@110 { // We rethrow the exception, but do nothing extra. This is just extra // overhead and should not be done. throw; } try { ... } catch (Exception e) // <-- Violation 8@110 { // We do something here, but nothing with the exception argument. i = 0; j = 0; } try { ... } catch (Exception e) { // This is fine, since we trace the exception System.Diagnostics.Trace.WriteLine(e.ToString()); } try { ... } catch (Exception e) { // This is fine, the original exception is used as inner exception for a more // specific exception. throw new MySpecificException(e); } |