SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Program Flow Logic → Exception Handling → Class-Based Exceptions → TRY →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.
... 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
... 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:
The object reference variable can be used to access the attributes and methods of the exception object.
Example
Catches exceptions with an inline declaration of an object reference variable. The static type of this variable is cx.
CLASS cx DEFINITION INHERITING FROM cx_dynamic_check.
PUBLIC SECTION.
ENDCLASS.
CLASS cy DEFINITION INHERITING FROM cx.
PUBLIC SECTION.
ENDCLASS.
TRY.
...
CATCH cy cx INTO DATA(oref).
ENDTRY.