RAISE EXCEPTION

Short Reference

Syntax

RAISE EXCEPTION { {TYPE cx_class [EXPORTING p1 = a1 p2 = a2 ...]}
                | oref }.

Effect

This statement interrupts the execution of the current statement block and triggers a class-based exception. It can appear at every stage of a processing block.

If the addition TYPE is specified, an exception of the exception class cx_class is raised and - if necessary - an exception object is created. After TYPE, every exception class cx_class visible at this point can be specified. With the addition EXPORTING, you can assign appropriate actual parameters to the input parameters of the instance constructor using the same syntax as with CREATE OBJECT.

If oref is specified, no new exception object is created during the trigger. For oref, an object reference variable must be specified which refers to an already existing exception object.

The statement RAISE EXCEPTION rules out the simultaneous use of the statement CATCHSYSTEM-EXCEPTIONS to handle catchable runtime errors, and the statements RAISE or MESSAGE RAISING to trigger non class-based exceptions in function modules and methods in the current processing block.

Note

When using the TYPE addition, due to performance reasons, an exception object is only created when it is required -, that is, when an appropriate CATCH block or CLEANUP block with the addition INTO is listed in an environmental TRY control structure. In principle, exceptions can be considered exception objects. A difference in behavior only exists when a non-catchable exception of the instance constructor replaces the original exception during the object creation. This case is very unlikely.

Example

Explicit triggering of a predefined exception for which an exception text other than the standard exception text is selected and whose placeholder &TOKEN& is filled by passing a value of the attribute with the same name.

DATA: exc  TYPE REF TO cx_sy_dynamic_osql_semantics,
      text TYPE string.

TRY.
    ...
    RAISE EXCEPTION TYPE cx_sy_dynamic_osql_semantics
      EXPORTING textid = cx_sy_dynamic_osql_semantics=>unknown_table_name
                token  = 'Test'.
    ...
  CATCH cx_sy_dynamic_osql_semantics INTO exc.
    text = exc->get_text( ).
    MESSAGE text TYPE 'I'.
ENDTRY.