Show TOC

Extracting an Exception Variable from a RAISE StatementLocate this document in the navigation structure

You can add a variable declaration for an exception to the method signature as well as to source code in order to instantiate the exception before raising it. This enables you to handle the result of the exception, for example, to display it in a message.

Prerequisites

This functionality is provided since SAP NetWeaver 7.4 SP05 / SAP NetWeaver 7.3 EHP1 SP11 and higher.

Context

Example

Before Execution After Execution

To copy the source code example, click here Code Example Before Execution

In the implementation of the drive method, an exception with the cx_error type is raised when the i_speed variable is less than zero.

In the signature of the drive method, the exc exception variable is added with TYPE REF TO of the selected exception class. In addition, this exception variable is added in a CREATE statement and called in a RAISE statement. The former RAISE EXCEPTION TYPE statement is deleted.

You can now reuse or process the value of the exception variable in order to handle this case of an exception.

Procedure

  1. In the implementation part, select the exception class where it is called in the RAISE EXCEPTION statement.
  2. Get the quick assist proposals by choosing Quick Fix from the context menu (shortcut Ctrl 1) or by using the Quick Assist view.
  3. Apply Extract Raise Variable.