‎2005 Apr 04 7:15 PM
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?
‎2005 Apr 04 8:26 PM
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>
‎2005 Apr 04 8:26 PM
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>
‎2005 Apr 04 8:41 PM