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.
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. |