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

RAISE EXCEPTION

Quick Reference

Syntax

RAISE [RESUMABLE] EXCEPTION
  { {TYPE cx_class [ message] [EXPORTING p1 = a1 p2 = a2 ...]}

  | oref }.

Extras:

1. ... RESUMABLE

2. ... EXPORTING p1 = a1 p2 = a2 ...

Effect

This statement interrupts execution of the current statement block and raises a class-based exception. It can be used at any point in a processing block. The statement interrupts the program flow and searches for a handler as described in System Response After a Class-Based Exception. Depending on the definition of the handler, the context of the exception is closed before or after the handler is executed. Some cleanup tasks may be performed here. During handling, processing can only be resumed again after the statement RAISE EXCEPTION (and without closing the context) if the addition RESUMABLE is specified.

The statement RAISE EXCEPTION must not be used in a method or function module in whose interface non-class-based exceptions are declared. Also, this statement does not permit simultaneous use of the statement CATCHSYSTEM-EXCEPTIONS for the obsolete handling of catchable runtime errors or RAISE or MESSAGE RAISING for raising non-class-based exceptions in function modules and methods in the current processing block.

Notes

Example

Raising an exception cx_demo in a method.

CLASS cx_demo DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.

CLASS cls DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS meth RAISING cx_demo.
ENDCLASS.

CLASS cls IMPLEMENTATION.
  METHOD meth.
    ...
    RAISE EXCEPTION TYPE cx_demo.
    ...
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  TRY.
      cls=>meth( ).
    CATCH cx_demo.
      cl_demo_output=>display( 'Catching exception' ).
  ENDTRY.

Example

Raising a caught exception of the class cx_demo again using the exception object.

CLASS cx_demo DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.

START-OF-SELECTION.
  TRY.
      TRY.
          RAISE EXCEPTION TYPE cx_demo.
        CATCH cx_demo INTO DATA(exc).
          cl_demo_output=>write( 'Inner CATCH' ).
          RAISE EXCEPTION exc.
      ENDTRY.
    CATCH cx_demo.
      cl_demo_output=>write( 'Outer CATCH' ).
  ENDTRY.
  cl_demo_output=>display( ).

Executable Example

Exceptions, RAISE

Addition 1

... RESUMABLE

Effect

The addition RESUMABLE raises an exception as a resumable exception. When an exception of this type is handled in a CATCH block, the statement RESUME can be used to jump back to directly before the raising statement, as long as the context of the exception was not deleted before the exception was handled.

Notes

Example

Raising a resumable exception cx_demo with the addition RESUMABLE in a method.

CLASS cx_demo DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.

CLASS cls DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS meth RAISING RESUMABLE(cx_demo).
ENDCLASS.

CLASS cls IMPLEMENTATION.
  METHOD meth.
    ...
    RAISE RESUMABLE EXCEPTION TYPE cx_demo.
    cl_demo_output=>display( 'Resumed ...' ).
    ...
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  TRY.
      cls=>meth( ).
    CATCH BEFORE UNWIND cx_demo.
      RESUME.
  ENDTRY.

Addition 2

... EXPORTING p1 = a1 p2 = a2 ...

Effect

The addition EXPORTING can be used to assign suitable actual parameters to the input parameters of the instance constructor of the exception class. The syntax is the same as for the statement CREATE OBJECT.

As in regular method calls, a1, a2, ... are general expression positions. In other words, functions and expressions can be passed as actual parameters, alongside data objects. Special rules apply in this case.

Note

Only the constants of the exception class that specify a static exception text of the exception class should be passed to the TEXTID input parameters of the instance constructor of the exception class. The addition MESSAGE is used to associate any messages with an exception. This addition cannot be specified with the parameter TEXTID.

Example

Explicitly raises 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 to the attribute with the same name.

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 DATA(exc).
    MESSAGE exc->get_text( ) TYPE 'I'.
ENDTRY.



Continue
RAISE EXCEPTION - message