Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Handle this exception, rather than masking it with a "NULL;" statement
-
Default Severity:Minor
-
Impact:Low
-
Likelihood:Low
-
Default Quality Profiles:Sonar way
-
Legacy Key:MaskedExceptionCheck
-
Covered Languages:C#, C, C++, Objective-C, PL/SQL
-
Remediation Function:Constant/Issue
-
Constant Cost:1h
-
Analysis Scope:Main Sources
-
Implementation details:
-
Common Rule:Yes
-
CWE:CWE-391
-
OWASP:A10
-
ReSharper:EmptyGeneralCatchClause
Description
When exceptions occur, it is usually a bad idea to simply ignore them. Instead, it is better to handle them properly, or at least to log them.
Noncompliant Code Example
SET SERVEROUTPUT ON DECLARE d VARCHAR2(1); BEGIN SELECT dummy INTO d FROM DUAL WHERE dummy = 'Y'; -- Will raise NO_DATA_FOUND DBMS_OUTPUT.PUT_LINE('d = ' || d); EXCEPTION WHEN NO_DATA_FOUND THEN -- Noncompliant, did we really want to mask this exception? NULL; END; /
Compliant Solution
SET SERVEROUTPUT ON DECLARE d VARCHAR2(1); BEGIN SELECT dummy INTO d FROM DUAL WHERE dummy = 'Y'; -- Will raise NO_DATA_FOUND DBMS_OUTPUT.PUT_LINE('d = ' || d); EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('Error: No data found'); END; /
See
- OWASP Top 10 2017 Category A10 - Insufficient Logging & Monitoring
- MITRE, CWE-391 - Unchecked Error Condition
Attachments
Issue Links
- deprecates
-
RSPEC-1674 "CATCH" clauses should not be empty
- Deprecated
- is duplicated by
-
RSPEC-1169 At least one exception should be handled in an exception block
- Closed
- is implemented by
-
SONARPY-524 Rule S2486: Exceptions should not be ignored
-
- Open
-
-
CPP-1444 Rule: Exceptions should not be ignored
-
- Closed
-
-
CPP-2900 S2486: move from vulnerability to code smell
-
- Closed
-
-
SONARJAVA-1469 Rule S2486: Exceptions should not be ignored
-
- Closed
-
- is related to
-
RSPEC-2002 Errors should not be silenced
- Active
- relates to
-
RSPEC-1166 Exception handlers should preserve the original exceptions
- Active
1.
|
C#: Generic exceptions should not be ignored | RSPEC-2748 |
|
Active | Unassigned | |
2.
|
Java | RSPEC-3487 |
|
Active | Unassigned | |
3.
|
RPG: "ON-ERROR" clauses should not be empty | RSPEC-2804 |
|
Active | Unassigned | |
4.
|
C-Family | RSPEC-3683 |
|
Active | Unassigned | |
5.
|
Cobol: Error conditions should not be ignored | RSPEC-3704 |
|
Active | Unassigned | |
6.
|
PL/SQL | RSPEC-4395 |
|
Active | Unassigned | |
7.
|
Python | RSPEC-5449 |
|
Active | Unassigned |