Resume Execution After a Resumable Exception
In the example, shown in the figure, method GET_TECH_ATTR raises and propagates the exception; the constructor propagates the exception further. All raising and propagating is setup to be resumable. The main program handles the exception with CATCH BEFORE UNWIND ..., checks that the exception indeed is resumable, and issues the RESUME statement. The system resumes the execution of GET_TECH_ATTR immediately after the RAISE RESUMABLE EXCEPTION statement is executed.
Hint: In this example, you keep the context of the exception. Without the BEFORE UNWIND addition, the system deletes the newly created instance before executing the CATCH block. Resuming the GET_GET_TECH_ATTR method and the constructor would not be possible.
Exception Mapping
After catching an exception, the program can raise a second exception, and so on. An exception object becomes invalid once the program leaves the CATCH block. Therefore, the handler on the top level can only access the last exception object. However, you can chain exception objects, that is, you can let one exception object point to the one before, which points to the one before it, and so on. The handler of an exception may follow the chain and evaluates each exception object in the sequence.
All exception classes provide a public instance attribute PREVIOUS. You type the attribute with REF TO CX_ROOT to point to arbitrary exception objects. The constructors of all exception classes have an import parameter, PREVIOUS, of the same type, which can be used to link an existing exception object to a new one.
In the example in the figure, the constructor catches the exception that has been raised by the GET_TECH_ATTR method. After analyzing the exception, the constructor raises a new exception of a different exception class. It chains the existing exception object to the new one by passing a reference to the existing object to the constructor of the new object. As a result, attribute PREVIOUS of the new exception object points to the exception object that preceded it.
The main program catches the second exception and accesses to the second exception object. However, by using public attribute PREVIOUS, the main program can navigate to the other exception object and analyze it. The main program can access each instance in a chain of exceptions and follow the history of the raised exceptions in the call hierarchy.
Implementation of Re-Raise Exceptions
You raise class-based exceptions with one of the following variants of statement RAISE EXCEPTION:
In the example, the constructor catches exception CX_EXC, which is raised by the GET_TECH_ATTR method. The constructor analyzes the exception object, performs necessary adjustments, issues a warning, and so on. The constructor then decides to pass the exception to the main program, where the exception is handled again.