Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Narrow this "{{CATCH}}" to a more specific exception exception type
-
Default Severity:Critical
-
Impact:High
-
Likelihood:Low
-
Default Quality Profiles:Sonar way
-
Covered Languages:ABAP
-
Remediation Function:Constant/Issue
-
Constant Cost:10min
Description
Because CX_ROOT is the base exception type, catching it directly probably casts a wider net than you intended. Catching CX_ROOT could mask far more serious system errors that your CATCH logic was intended to deal with.
Some smaller, more specific exception type should be caught instead.
Noncompliant Code Example
try. if ABS( NUMBER ) > 100. write / 'Number is large'. endif. catch CX_ROOT into OREF. write / OREF->GET_TEXT( ). endtry.
Compliant Solution
try. if ABS( NUMBER ) > 100. write / 'Number is large'. endif. catch CX_SY_ARITHMETIC_ERROR into OREF. write / OREF->GET_TEXT( ). endtry.
Attachments
Issue Links
- is implemented by
-
SONARABAP-247 Rule: "CX_ROOT" should not be caught
-
- Closed
-
- is related to
-
RSPEC-1181 Throwable and Error should not be caught
- Active