Skip to content

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

CATCH

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CATCH [BEFORE UNWIND] cx_class1 cx_class2 ... [INTO oref]. 

Extras

1. ... BEFORE UNWIND
2. ... INTO oref

Effect

Introduction of a CATCH block of a TRY control structure in which exceptions can be handled.

A CATCH block is an exception handler, meaning the program logic that is executed whenever the associated exception is raised in the TRY block of the same TRY control structure.

A CATCH block handles the exceptions of the exception classes cx_class1 cx_class2 ... that are specified after the statement CATCH as well as the exceptions of the subclasses of these exception classes. In each CATCH statement of a TRY control structure, you can list any number of exception classes cx_class1 cx_class2 ..., whereby more special exception classes (subclasses) must be listed before more general exception classes (superclasses). This order must be kept both within a CATCH statement and across multiple CATCH statements of a TRY control structure.


Note

The rule whereby CATCH special exception classes must be listed before general classes ensures that an exception is not handled by a general exception handler (superclass) if a special handler (subclass) is provided.

Addition 1

... BEFORE UNWIND

Effect

If the addition BEFORE UNWIND is specified, the context in which the exception was raised, including all called procedures and their local data, is deleted only after exiting the CATCH block. If the addition is not specified, the context is deleted before the CATCH block is executed.


Notes

  • If the addition BEFORE UNWIND is specified, the statement RESUME can be used in the CATCH block for handling a resumable exception, to resume processing after the statement that raised the exception. This is the only case in which the context of the exception is not deleted when the CATCH block is exited.
  • Resumable exceptions can also be handled in CATCH blocks without the addition BEFORE UNWIND. In this case, the context of the exception is deleted before the handling process and the statement RESUME cannot be specified.
  • Any CLEANUP blocks are always executed directly before their context is deleted. If BEFORE UNWIND is used, after exception handling, and in all other cases before the exception handling.
  • Use of the addition BEFORE UNWIND for CATCH is only required when you use the statement RESUME. However, it is allowed in principle during exception handling if the context of the exception is to be evaluated before any cleanup activities in CLEANUP blocks. This makes sense, for example, when handling resource bottlenecks if releasing resources in CLEANUP blocks would change the context and thus make the calculation of the free resources in the exception handler meaningless. Other than for logging purposes, we do not recommend evaluating the part of the context that is only of interest locally for implementing the incorrect procedure.

Addition 2

... INTO oref

Effect

If the addition INTO is specified, a reference to the exception object is stored in oref, where oref must be an object reference variable whose static type is more general than or the same as the most general of the specified exception classes. oref can be used to access the attributes and methods of the exception object.