Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Divided by zero

Former Member
0 Likes
3,437

Hi,

I have suppose 3 stmts.

f1 = f2/f3.

f4 = f5/f6

f8 = f7/f5

I want to handle divided by zero exception. How do i handle that.

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,577

See this example.

data : val type I.
data OREF type ref to CX_ROOT.
data TEXT type STRING.
val = 0.

  try.
    if val = 0.
      raise exception type CX_SY_ZERODIVIDE.
  endif.
  catch CX_SY_ZERODIVIDE into OREF.
    TEXT = OREF->GET_TEXT( ).
    write : / Text.
endtry.

3 REPLIES 3
Read only

Former Member
0 Likes
1,577

You can write any conditional statement such as case, if...endif. for your purpose

Read only

Former Member
0 Likes
1,578

See this example.

data : val type I.
data OREF type ref to CX_ROOT.
data TEXT type STRING.
val = 0.

  try.
    if val = 0.
      raise exception type CX_SY_ZERODIVIDE.
  endif.
  catch CX_SY_ZERODIVIDE into OREF.
    TEXT = OREF->GET_TEXT( ).
    write : / Text.
endtry.

Read only

Former Member
1,577

DATA temp TYPE I.

temp = 10.

TRY.

temp = temp / 0.

CATCH cx_sy_zerodivide.

MESSAGE 'Oh noes ' TYPE 'E'.

ENDTRY.

WRITE / temp.