Skip to content

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_EXC

Technical Details ​

Released under the MIT License.