Application Development 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: 

Divided by zero

Former Member
0 Kudos
2,194

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

Former Member
0 Kudos
334

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

Former Member
0 Kudos
334

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

Former Member
0 Kudos
335

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.

Former Member
334

DATA temp TYPE I.

temp = 10.

TRY.

temp = temp / 0.

CATCH cx_sy_zerodivide.

MESSAGE 'Oh noes ' TYPE 'E'.

ENDTRY.

WRITE / temp.