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

Exception Handling

Former Member
0 Likes
413

Right now i'm studying the eLearning Material located at the ABAP Section (for more info: https://www.sdn.sap.com/sdn/developerareas/abap.sdn?node=linkDnode6-3)

I got a doubt reading this stuff. How i can use the methods of the Exception GET_TEXT and GET_SOURCE_POSITION that belongs to the exeption's class?

  TRY.
     Z = 1 / 0. "ZERO DIVISION    
 
    CATCH cx_root INTO ex.


  ENDTRY.

Where CX_ROOT has 2 methods of it own: 1) GET_TEXT, 2) GET_SOURCE_POSITION

Any idea?

1 ACCEPTED SOLUTION
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
354

Hi Carlos

Inspect this standard example:


...
parameters NUMBER type I.

data RESULT type P decimals 2.
data OREF type ref to CX_ROOT.
data TEXT type STRING.

start-of-selection.

  write: / 'Testing division and Sqare root with', NUMBER.
  uline.

    try.
    if ABS( NUMBER ) > 100.
      raise exception type CX_DEMO_ABS_TOO_LARGE.
    endif.
    try.
      RESULT =  1 / NUMBER.
      write: / 'Result of division:', RESULT.
      RESULT = SQRT( NUMBER ).
      write: / 'Result of square root:', RESULT.
      catch CX_SY_ZERODIVIDE into OREF.
      TEXT = OREF->GET_TEXT( ).
      cleanup.
        clear RESULT.
    endtry.
    catch CX_SY_ARITHMETIC_ERROR into OREF.
      TEXT = OREF->GET_TEXT( ).
    catch CX_ROOT into OREF.
      TEXT = OREF->GET_TEXT( ).
    endtry.
    if not TEXT is initial.
      write / TEXT.
    endif.
    write: / 'Final result:', RESULT.

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

2 REPLIES 2
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
355

Hi Carlos

Inspect this standard example:


...
parameters NUMBER type I.

data RESULT type P decimals 2.
data OREF type ref to CX_ROOT.
data TEXT type STRING.

start-of-selection.

  write: / 'Testing division and Sqare root with', NUMBER.
  uline.

    try.
    if ABS( NUMBER ) > 100.
      raise exception type CX_DEMO_ABS_TOO_LARGE.
    endif.
    try.
      RESULT =  1 / NUMBER.
      write: / 'Result of division:', RESULT.
      RESULT = SQRT( NUMBER ).
      write: / 'Result of square root:', RESULT.
      catch CX_SY_ZERODIVIDE into OREF.
      TEXT = OREF->GET_TEXT( ).
      cleanup.
        clear RESULT.
    endtry.
    catch CX_SY_ARITHMETIC_ERROR into OREF.
      TEXT = OREF->GET_TEXT( ).
    catch CX_ROOT into OREF.
      TEXT = OREF->GET_TEXT( ).
    endtry.
    if not TEXT is initial.
      write / TEXT.
    endif.
    write: / 'Final result:', RESULT.

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

Read only

0 Likes
354

Serdar.. thank you very much...