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

Raising exception

former_member211992
Active Participant
0 Kudos
487

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Kudos
332

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

1 REPLY 1
Read only

Former Member
0 Kudos
333

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