ABAP Keyword Documentation → ABAP - Reference → Program Flow Logic → Exception Handling → Class-Based Exceptions → TRY
CLEANUP
Other versions: 7.31 | 7.40 | 7.54
Syntax
CLEANUP [INTO oref].
Addition
Effect
Introduces a statement block of a TRY control structure where cleanups can be performed.
A CLEANUP block is executed when a class-based exception in the TRY
block of the same TRY control structure is raised, but is handled in a
CATCH block of an external TRY control structure. A CLEANUP block is executed immediately before the context of the exception is deleted:
-
If the addition
BEFORE UNWINDis specified for the handlingCATCHblock, the context is deleted when theCATCHblock is exited and theCLEANUPblock is executed accordingly after handling. -
If the addition
BEFORE UNWINDis not specified, the context is deleted before theCATCHblock is executed and theCLEANUPblock is executed accordingly. -
If
RESUMEis used to resume processing after a resumable exception, the context is not deleted and accordingly noCLEANUPblock is executed.
The CLEANUP block must be executed completely and must be exited using
ENDTRY so that the exception can be propagated to its handler. If an attempt is made to exit
the context of a CLEANUP block prematurely, a runtime error occurs. A CLEANUP block cannot contain any
statements where the system can detect (statically)
that it cannot return to the CLEANUP block. Program calls using
SUBMIT and CALL TRANSACTION should also be avoided here.
Notes
-
The context of the
TRYblock can be cleaned up in aCLEANUPblock. For example, objects can be updated to a consistent state or external resources released to which an external handler would no longer have access. -
Since a
CLEANUPblock must always be executed completely, all the exceptions raised there must also be handled there.
Addition
... INTO oref
Effect
If the addition INTO is specified, a reference to the exception object is saved to oref. The following can be specified for oref:
- An existing object reference variable of the type CX_ROOT
-
An inline declaration
DATA(var), where an object reference variable of the type CX_ROOT is declared.
oref can be used to access the exception object.
Note
Within the CLEANUP block, do not raise the current exception again using
RAISE EXCEPTION oref, since this would modify the attributes of the exception object.