Show TOC

Extracting a Catch VariableLocate this document in the navigation structure

You can add a local variable to the method signature. Its type refers to the raised exception of the calling method. In addition, this local variable is added as an INTO clause to the already existing CATCH block. This enables you to handle the result of the exception in order, for example, to display it in a message.

Prerequisites

This functionality is provided since SAP NetWeaver 7.5 SP00.

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, the check_fuel method is called in a TRY CATCH block. Here, the cx_no_fuel exception that is raised in the public section is handled.

The result of the exception now needs be handeld as a local variable after it is raised.

In the signature of the drive method, the exc local variable is added with TYPE REF TO of the selected exception class. In addition, this local variable is added as an INTO clause at the end of the CATCH statement.

Procedure

  1. In the implementation part, select the CATCH statement where the exception class is called.
  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 Catch Variable.