You can surround the selected block of statements with a TRY CATCH statement in order to handle raised exception(s) as a single or multiple TRY CATCH block.
Example with Single CATCH
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 and check_engine methods are called. The check_fuel and check_engine methods raise an exception of the cx_failure and cx_no_fuel types. The signature of the drive method does not contain any exception. In the drive method, the selection contains the call of the check_fuel and check_engine methods that can raise exceptions. You want to handle the cx_no_fuel and cx_failure exceptions that might occur in the drive method. |
In the drive method, the selection contains the call of the check_fuel and check_engine methods that can raise exceptions. You want to handle the cx_no_fuel and cx_failure exceptions that might occur in the drive method. |
Example with Multi CATCH
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 and check_engine methods are called. The check_fuel and check_engine methods raise an exception of the cx_failure and cx_no_fuel types. The signature of the drive method does not contain any exception. |
A TRY CATCH block is added to the drive method. If you have selected the call, a CATCH block for each exception (cx_no_fuel and cx_failure) is added. Inside each CATCH block, you can add code to handle the exceptions. |
To handle this, ABAP Development Tools (ADT) provides two options: