Google Search - Blog...........

ABAP - OOPS: Instance Constructors Can Raise Exceptions In Method Programming.

REPORT YSUBOOPS2.

CLASS c1 DEFINITION.
PUBLIC SECTION.
METHODS : CONSTRUCTOR importing num type i
exceptions e1 .
ENDCLASS.

CLASS C1 IMPLEMENTATION.
METHOD constructor.
if num lt 7.
raise e1.
endif.
ENDMETHOD.
ENDCLASS.
*************** main program **************
START-OF-SELECTION.
DATA: obj1 TYPE REF TO c1.
CREATE OBJECT: obj1 exporting num = 5
exceptions e1 = 2.
if sy-subrc = 2.
write:/5 'Exceptions raised'.
endif.

Output Exceptions Raised

No comments:

Post a Comment