Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Program Flow →  Exception Handling →  Class-Based Exceptions →  TRY 

CLEANUP

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CLEANUP [INTO oref]. 

Addition

... INTO oref

Effect

Introduction to a statement block of a TRY control structure in which a cleanup can be performed.

A CLEANUP block is executed exactly when a class-based exception in the TRY block of the same TRY control structure occurs, 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 addition BEFORE UNWIND is specified for the handling CATCH block, the context is deleted when you leave the CATCH block and the CLEANUP block is executed accordingly after handling.
  • If addition BEFORE UNWIND is not specified, the context is deleted before the CATCH block is executed and the CLEANUP block is executed accordingly.
  • If processing with RESUME is restarted after a restartable exception, the context is not deleted and accordingly no CLEANUP block is executed.

The CLEANUP block must be executed completely and must be left with ENDTRY so that the exception can be propagated to your handler. If you try to leave the context of a CLEANUP block prematurely, a runtime error occurs. No statements can be listed for which you can see statically that you cannot return to the CLEANUP block.


Notes

You can clean up the context of the TRY block in a CLEANUP block. For example, you can bring objects to a consistent state or release external resources which an external handler no longer had access to.

  • Since a CLEANUP block must always be executed completely, all the exceptions raised there must also be handled there.

Addition

... INTO oref

Effect

If addition INTO is specified, a reference to the exception object in oref is stored, whereby oref must be an object reference variable of type CX_ROOT. You can access the exception object with oref.


Note

In the CLEANUP block, the current exception should not be triggered again with RAISE EXCEPTION oref, as this would change the attributes of the exception object.