ABAP Keyword Documentation → ABAP - Reference → Program Flow Logic → Exception Handling → Class-Based Exceptions
RAISE EXCEPTION
Other versions: 7.31 | 7.40 | 7.54
Syntax
RAISE [RESUMABLE] EXCEPTION
{ {TYPE cx_class [EXPORTING p1 = a1 p2 = a2 ...]}
| oref }.
Addition
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; this can include
cleanup tasks. Only if the addition RESUMABLE
is specified can processing be resumed again after the statement RAISE EXCEPTION
during handling, without closing the context.
If the addition TYPE
is specified, an exception of exception class
cx_class is raised and, if necessary, an exception object is created. Every exception class
cx_class visible at this point can be specified after TYPE
. The addition
EXPORTING
can be used to assign appropriate actual parameters to the input
parameters of the instance constructor of the exception class by using the same syntax as used for
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.
If oref
is specified, no new exception object is created when the exception
is raised. For oref
, an object reference variable must be specified that
references an existing exception object. In the existing exception object, the internal attributes that
describe the position of the exception and that are read using the method GET_SOURCE_POSITION, are applied
at the position of the statement RAISE
. In addition, the attribute IS_RESUMABLE is set to a new value, depending on how the addition RESUMABLE
is used.
The statement RAISE EXCEPTION
must not be used in a method or function module in whose interface
non-class-based exceptions are declared. Also,
the statement does not permit simultaneous use of the statement CATCHSYSTEM-EXCEPTIONS
for the obsolete handling of
catchable runtime
errors, and the statements RAISE
or MESSAGE RAISING
to raise non-class-based exceptions in function modules and methods in the current processing block.
Notes
-
If the addition
TYPE
is used, an exception object is only created when required, for performance reasons, that is, when an appropriateCATCH
orCLEANUP
block with the additionINTO
is used in a surroundingTRY
control structure. In principle, an exception is the same thing as an exception object being generated. A difference in behavior can occur only if a non-handled exception of the instance constructor replaces the original exception when the object is generated. However, this situation should never arise. -
If
oref
is specified, either an exception object instantiated using CREATE OBJECT can be used, or an exception that was previously caught during exception handling can be raised again. -
If a caught exception is raised again, note that the exception object does not remain unmodified and
that the information about the position of the exception is changed. If the original information is
to be propagated to an external handler, a new exception from the same class can be raised. The original
exception object is then passed to the parameter PREVIOUS of the constructor of this class. It may be
enough to propagate the original exception implicitly (and not raise it again using
RAISE
). The corresponding original exception can then be evaluated in theCLEANUP
block, if required - If a procedure is exited by raising an exception, the content of the formal parameter for which the pass by value is defined is not assigned to the respective actual parameters.
- Only the constants of the exception class that specify an exception text of the exception class should be passed to the TEXTID input parameters of the instance constructor of the exception class.
-
The addition
THROW
in a conditional expression makes it possible to raise a class-based exception in an operand position.
Example
See Exceptions, RAISE
.
Example
A predefined exception is raised explicitly 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.
DATA exc TYPE REF TO cx_sy_dynamic_osql_semantics.
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.
MESSAGE exc->get_text( ) TYPE 'I'.
ENDTRY.
Addition
... 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
-
If the statement
RESUMABLE
is used to raise an exception as a resumable exception, the handler has to determine whether processing is resumed afterRAISE EXCEPTION
, or whether processing for the current context is canceled completely. Both alternatives can occur when an exception is raised. It is important to note thatCLEANUP
blocks are only executed when the context is deleted. -
When exceptions of the types CX_STATIC_CHECK and CX_DYNAMIC_CHECK (which are raised as resumable) are
propagated, they can become non-resumable if the addition
RESUMABLE
is not specified for the additionRAISING
(for declaring the exception) in each interface involved. -
When exceptions of type CX_NO_CHECK are propagated, the resumable attribute is always retained. However,
caution should be used when raising exceptions of type CX_NO_CHECK as resumable, and it is important to ensure a procedure always displays the required behavior.