Avoid CATCH Blocks That Only Re-raise the Same Exception
WarningAnti-Patterns & Bad Practices#EC NO_CATCH_RERAISERemote Enabled
Overview
Detect CATCH blocks that only re-raise the same exception.
ATC Finding Message:
CATCH block only re-raises the same exception; remove it
Rationale
A CATCH block whose only statement re-raises the identical exception type adds no value: the handler is logically transparent and only adds noise, stack depth and maintenance cost. Either remove the CATCH clause and let the exception propagate, or enrich it with context (previous, a domain exception, or message text). This rule only reports blocks that consist of exactly one bare re-raise statement.
Non-Compliant
abap
TRY.
lo_service->run( ).
CATCH zcx_service_error.
RAISE EXCEPTION TYPE zcx_service_error.
ENDTRY.Compliant
abap
TRY.
lo_service->run( ).
CATCH zcx_service_error INTO lx_error.
RAISE EXCEPTION NEW zcx_service_error( previous = lx_error ).
ENDTRY.Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC NO_CATCH_RERAISE
" SAP CI_ prefix format:
... "#EC CI_NO_CATCH_RERAISERelated Rules
- Avoid Catching Generic CX_ROOT (Catch Specific Exceptions) —
#EC NO_CATCH_ROOT - Preserve the Original Exception with PREVIOUS —
#EC NO_EXC_CHAIN - Avoid Empty Control Blocks —
#EC NO_EMPTY_BLOCK
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_CATCH_RERAISE - Implementation File: zcl_skylint_no_catch_reraise.clas.abap