Raise At Most One Exception Class per Method
WarningClean ABAP & Modern Syntax#EC NO_MULTI_EXCRemote Enabled
Overview
Raise At Most One Exception Type per Method.
ATC Finding Message:
Method raises several different exception classes - raise one type instead
Rationale
Throwing several different exception classes from one method forces each caller to nest separate TRY/CATCH blocks and duplicate handler logic. Define a single dedicated exception type per method's interface (or a single hierarchy family) so the caller can react with one handler; packing more error detail into the exception's attributes keeps the API stable. Clean ABAP (Throw one type of exception) recommends one main exception class per method.
Non-Compliant
abap
METHOD add_row.
IF rows_full.
RAISE EXCEPTION TYPE cx_full.
ENDIF.
IF invalid_row.
RAISE EXCEPTION TYPE cx_invalid.
ENDIF.
ENDMETHOD.Compliant
abap
METHOD add_row.
RAISE EXCEPTION TYPE cx_my_add_row
EXPORTING iv_reason = reason.
ENDMETHOD.Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC NO_MULTI_EXC
" SAP CI_ prefix format:
... "#EC CI_NO_MULTI_EXCRelated Rules
- Prefer Class-Based Exceptions over Classic EXCEPTIONS —
#EC PREF_CLASS_EXC - Classic EXCEPTIONS must not map two errors to the same number —
#EC NO_EXC_OVERLAP - Avoid Obsolete MESSAGE ... RAISING in Methods —
#EC NO_MSG_RAISING
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_MULTI_EXC - Implementation File: zcl_skylint_no_multi_exc.clas.abap