ABAP Keyword Documentation → ABAP - Reference → Program Flow → Exception Handling → Class-Based Exceptions → Examples of Exceptions
Exceptions, RAISE
This example demonstrates the statement RAISE EXCEPTION
.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: oref TYPE REF TO cx_demo_constructor,
text TYPE string,
position TYPE i.
TRY.
TRY.
RAISE EXCEPTION TYPE cx_demo_constructor
EXPORTING
my_text = sy-repid.
CATCH cx_demo_constructor INTO oref.
text = oref->get_text( ).
oref->get_source_position(
IMPORTING source_line = position ).
WRITE: /(5) position, text.
RAISE EXCEPTION oref.
ENDTRY.
CATCH cx_demo_constructor INTO oref.
text = oref->get_text( ).
oref->get_source_position(
IMPORTING source_line = position ).
WRITE: /(5) position, text.
ENDTRY.
Description
This example shows the two variants of the RAISE EXCEPTION
statement. The
first statement raises an exception of class CX_DEMO_CONSTRUCTOR in the inner TRY
block, generates the relevant object, and passes the program name to the instance constructor. The inner
CATCH
block handles the exception, provides the exception text, and raises
the exception again without generating a new object. The outer CATCH
block
handles the exception again. The CX_DEMO_CONSTRUCTOR class is defined in such a way that the passed program name appears in the exception text. The generated instance constructor takes care of this.
The line number in which the exception was raised is shown to indicate that, when the existing exception object was reused, information relevant to this object was modified.