
You can add an exception to the method signature based on an existing RAISE EXCEPTION statement of the method implementation.
Example
In the implementation of the method drive, the exception speed_too_high is raised. This is to be reflected in the method signature by adding the exception to the RAISING clause. The exception class cx_ris_exception that relates to the exception raise_statement is to be defined in the public section:
CLASS cl_car_with_exception DEFINITION PUBLIC.
PUBLIC SECTION.
METHODS:
drive
IMPORTING
i_speed TYPE i.
ENDCLASS.
CLASS cl_car_with_exception IMPLEMENTATION.
METHODS drive.
IF i_speed > 240.
RAISE EXCEPTION TYPE cx_speed_too_high.
ENDIF.
ENDMETHOD.
ENDCLASS.In the signature of the drive method, the exception class cx_speed_too_high is added to the RAISING clause.
CLASS cl_car_with_exception DEFINITION PUBLIC.
PUBLIC SECTION.
METHODS:
drive
IMPORTING
i_speed TYPE i.
RAISING
cx_speed_too_high.
ENDCLASS.
CLASS cl_car_with_exception IMPLEMENTATION.
METHODS drive.
IF i_speed > 240.
RAISE EXCEPTION TYPE cx_speed_too_high.
ENDIF.
ENDMETHOD.
ENDCLASS.