Skip to Content
0

Raising exception

Dec 14, 2016 at 11:30 AM

60

avatar image

Dear all

here is my coding snipet

CLASS lcl_myclass DEFINITION.
PUBLIC SECTION.

CLASS-METHODS:
" use exception class
divide
IMPORTING
id_enumerator TYPE i
id_denominator TYPE i
RETURNING
value(rd_result) TYPE i
RAISING
cx_sy_zerodivide,

" use exception class
divide_2
IMPORTING
id_enumerator TYPE i
id_denominator TYPE i
RETURNING
value(rd_result) TYPE i
RAISING
cx_sy_zerodivide.

ENDCLASS. "lcl_myclass DEFINITION

CLASS lcl_myclass IMPLEMENTATION.

METHOD divide.


rd_result = id_enumerator / id_denominator.


ENDMETHOD. "divide


METHOD divide_2.

IF ( id_denominator = 0 ).
RAISE EXCEPTION TYPE cx_sy_zerodivide
EXPORTING
textid = cx_sy_zerodivide=>cx_sy_arithmetic_error
operation = 'DIVIDE'.

ELSE.
rd_result = id_enumerator / id_denominator.
ENDIF.


ENDMETHOD. "divide_2

DATA: go_error TYPE REF TO cx_root,
gd_msg TYPE bapi_msg.

DATA: go_myclass TYPE REF TO lcl_myclass,
gd_result TYPE i.

PARAMETER:
p_enum TYPE i DEFAULT '10',
p_denom TYPE i DEFAULT '1'.

START-OF-SELECTION.


TRY.
CALL METHOD lcl_myclass=>divide
EXPORTING
id_enumerator = p_enum
id_denominator = p_denom
RECEIVING
rd_result = gd_result.

WRITE: / p_enum, '/', p_denom, '=', gd_result.

CATCH cx_sy_zerodivide INTO go_error.
gd_msg = go_error->get_text( ).
MESSAGE gd_msg TYPE 'I'.
ENDTRY.


TRY.
CALL METHOD lcl_myclass=>divide_2
EXPORTING
id_enumerator = p_enum
id_denominator = p_denom
RECEIVING
rd_result = gd_result.

WRITE: / p_enum, '/', p_denom, '=', gd_result.

CATCH cx_sy_zerodivide INTO go_error.
gd_msg = go_error->get_text( ).
MESSAGE gd_msg TYPE 'I'.
ENDTRY.

here in method divide_2 i used syntax raise exception and catching the exception in the instance call but in method divide i have not used raise exception clause but used catch in the instance but how it catching the exception which i havenot raised , there is no dump at all..in divide_2 i have used condition IF ( id_denominator = 0 ). but in divide i havenot used anything then how exception finding id_denominator = 0 .

HElp me in this

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
max bianchi Dec 14, 2016 at 01:45 PM
0

Hi

You haven't a dump becuase the method is called between TRY/ENDTRY and so the "dump" is catched by system excption cx_sy_zerodivide

Max

Share
10 |10000 characters needed characters left characters exceeded