Report Z_YY_TEST_03.
parameters number type i.
data result type p decimals 2.
data oref type ref to cx_root.
data text type string.
start-of-selection.
try.
if abs( number ) > 100.
raise exception type cx_demo_abs_too_large. "RAISE EXCEPTION手动触发异常
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."输出0时会在这里捕获
" catch cx_sy_arithmetic_error into oref."输出0时会在这里捕获
" text = oref->get_text( ).
" concatenate 'CATCH cx_sy_arithmetic_error : ’ text into text.
cleanup."当内层TRY发生了异常,且没有被捕获到,抛到外层TRY前会被执行
clear result.
write: / 'cleanup'.
endtry.
catch cx_sy_arithmetic_error into oref."输入负数会在这里捕获
text = oref->get_text( ).
concatenate 'CATCH cx_sy_arithmetic_error : ' text into text.
- catch cx_root into oref."输入的数大于100时会在这里捕获
catch cx_demo_abs_too_large into oref."输入的数大于100时会在这里捕获
text = oref->get_text( ).
concatenate 'CATCH cx_root : ’ text into text.
endtry.
if not text is initial.
write / text.
endif.
write: / ‘Final result:’ NO-GAP, result NO-GAP.
CALL FUNCTION ‘READ_TEXT’
EXPORTING
-
CLIENT = SY-MANDT ID = LANGUAGE = NAME = OBJECT =
-
ARCHIVE_HANDLE = 0
-
LOCAL_CAT = ' '
- IMPORTING
-
HEADER =
-
TABLESOLD_LINE_COUNTER =
LINES = - EXCEPTIONS
-
ID = 1
-
LANGUAGE = 2
-
NAME = 3
-
NOT_FOUND = 4
-
OBJECT = 5
-
REFERENCE_CHECK = 6
-
WRONG_ACCESS_TO_ARCHIVE = 7
-
IF SY-SUBRC <> 0.OTHERS = 8 .
- Implement suitable error handling here
ENDIF.