You are on page 1of 2

report z745oops23.

Handling Exceptions
(System-defined Exception messages)
data k type ref to cx_sy_zerodivide.
data lv_str type string.
data :lv_pname type sy-repid,
lv_iname type sy-repid,
lv_pos type i.
class abc definition.
public section.
methods m1 importing i_x type i i_y type i
exporting e_z type i.
endclass.
class abc implementation.
method m1.
try.
write :/ 'begin of method m1'.
e_z = i_x / i_y.
write :/ 'end of method m1'.
catch cx_sy_zerodivide into k.
call method k->if_message~get_text
receiving
result = lv_str.
write :/ 'Short exception message is ',lv_str.
uline.
clear lv_str.
call method k->if_message~get_longtext
receiving
result
= lv_str.
write :/ 'long exception message is ',lv_str.

uline.
call method k->get_source_position
importing
program_name = lv_pname
include_name = lv_iname
source_line = lv_pos.
write :/ 'Program name
/ 'Include name
/ 'Line no
uline.
endtry.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
parameters : p_x type i,
p_y type i.
data lv_z type i.
call method ob->m1
exporting
i_x = p_x
i_y = p_y
importing
e_z = lv_z.
write :/ 'Division is ',lv_z.
write :/ 'End of program..'.

:',lv_pname,
:',lv_iname,
:',lv_pos.

You might also like