ABAP Keyword Documentation → ABAP − Reference → Program Flow Logic → Exception Handling → Class-Based Exceptions
System Response after a Class-Based Exception
A class-based exception can be raised in a statement block for one of the following reasons:
- The exception is raised explicitly using the statement
RAISE EXCEPTION or the addition
THROW
in a conditional expression.
- The exception is raised implicitly by the ABAP runtime environment.
In both cases, the occurrence of a class-based exception interrupts the sequential processing of the current processing block, and the system responds as follows:
- If the exception is raised when a
TRY
block of aTRY
control structure is executed, an appropriateCATCH
block is searched as a handler. Execution of eachTRY
block opens a context, also called a protected area, into which the execution of otherTRY
blocks can be embedded. Usually, execution is embedded by calling procedures and less frequently by nesting TRY blocks in the source code. Starting at the position where the exception is raised, the system scans theTRY
control structures of the participatingTRY
blocks from the inside to the outside for the firstCATCH
block in which the exception class or one of its superclasses appears. If it finds aCATCH
block, there are two possible cases:
- If the addition
BEFORE UNWIND
is not declared in the statementCATCH
, the context in which the exception was raised is deleted, including all called procedures and their local data. TheCATCH
block is then executed.
- If the addition
BEFORE UNWIND
is declared in the statementCATCH
, theCATCH
block is executed immediately. If theCATCH
block is exited using the statementRESUME
in a resumable exception, the program resumes after the place where the exception was raised. In all other cases, the system deletes the context in which the exception was raised, after theCATCH
block is exited.
CATCH
block is not exited using a statement such as
RESUME
, RETRY
, or any other processing block
exits, processing continues after the TRY
control structure of the block.
- If no handlers are found in any of the participating
TRY
control structures of a protected area, or if the exception is not raised during processing of aTRY
block of aTRY
control structure, a runtime error occurs at the point where the exception was raised. The short dump of the runtime error contains the name of the exception class and the exception text. The attributes of the exception object can be displayed in transaction ST22.
Note the following special features:
- If the user leaves the procedure context during the handler search, the procedure's interface will be checked. Only exceptions declared there can be propagated from the procedure. Exceptions of the categories CX_STATIC_CHECK and CX_DYNAMIC_CHECK must be declared explicitly, while exceptions of category CX_NO_CHECK are always declared implicitly. If the exception is not declared in the interface, the exception of the predefined class CX_SY_NO_HANDLER is raised at the call position of the procedure, in whose attribute PREVIOUS a reference to the original exception is stored. This is done at the call position of the procedure,
- If a handler is found, the
CLEANUP
blocks of allTRY
control structures that were so far scanned unsuccessfully are executed from the inside to the outside, directly before their context is deleted. This means that, ifBEFORE UNWIND
is declared for theCATCH
block, theCLEANUP
blocks are executed when the handler is exited and are otherwise executed before being handled. Exceptions that are raised within aCLEANUP
block cannot exit the block and must be handled there.
NoCLEANUP
blocks are executed in the following cases:
- When the handling of a
resumable exception is exited using
RESUME
.
TRY
control structures whose exception is raised in aCATCH
block (aCATCH
block is not part of the protected range).
See also:
Other versions: 7.31 | 7.40 | 7.54