OOP ABAP Part 4: Class-Based Exceptions
Preview · a free account unlocks the full lesson
Handle errors the class-based way: TRY/CATCH/CLEANUP, RAISE EXCEPTION TYPE, the CX STATIC CHECK / CX DYNAMIC CHECK / CX NO CHECK hierarchy, custom exception classes with message texts, and how they compare with classic EXCEPTIONS and sy-subrc.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Class-based exceptions are objects: you raise one with RAISE EXCEPTION TYPE zcx_… and handle it with TRY … CATCH … ENDTRY. This matters because the methods built in Parts 1–3 simply wrote errors to the list, whereas reusable code needs to signal errors back to its caller instead.
For comparison, classic error handling works through function modules declaring EXCEPTIONS not_found = 1, with the caller checking sy-subrc after CALL FUNCTION. This style still exists throughout the system (BAPIs use a RETURN table instead), but it's easy to forget the sy-subrc check, and no further detail travels with the error.
The modern TRY / CATCH / CLEANUP construct looks like: TRY, call lo_service->book( … ); CATCH zcx_flight_error INTO lx_error, then MESSAGE lx_error TYPE 'I' DISPLAY LIKE 'E'; CLEANUP, which runs when the exception leaves this TRY block unhandled; ENDTRY. CATCH blocks are checked in order, so catch specific classes before general ones, leaving CX_ROOT last. Using INTO lx_error gives you the exception object itself, with get_text( ), a previous exception, and any custom attributes it carries.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
Keep exploring
Interview questions on this topic
Related SAP topics
Referenced SAP objects
Reviewed reference pages for the objects this page mentions.
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.