2023 Aug 21 9:41 AM
data: l_string type string.
try.
perform ztest_form_creat_sqlexception.
catch cx_sy_open_sql_db into data(err1).
l_string = | case A-1: { err1->get_text( ) }|.
catch cx_root into data(err2). " catched here
l_string = | case A-2: { err2->get_text( ) }|.
endtry.
message l_string type 'I' display like 'E'.
try.
perform ztest_form_creat_dynexception.
catch cx_sy_send_dynpro_no_receiver into data(err3). " catched here
l_string = | case B-1: { err3->get_text( ) }|.
catch cx_root into data(err4).
l_string = | case B-2: { err4->get_text( ) }|.
endtry.
message l_string type 'I' display like 'E'.
exit.
form ztest_form_creat_sqlexception.
raise exception type cx_sy_open_sql_db.
endform.
form ztest_form_creat_dynexception.
raise exception type cx_sy_send_dynpro_no_receiver.
endform.
With the code above, I get case A-2 and case B-1.
Is there any reason for having the different catching points with each exceptions?
Because if I cannot know the reason, I need to catch all excaptions with cx_root.
Thanks.
2023 Aug 21 12:22 PM
You need to use raising for non-dynamic exceptions.
form ztest_form_creat_sqlexception raising cx_sy_open_sql_db.
When you run your original program the error message actually tells you this.
case A-2: An exception with the type CX_SY_OPEN_SQL_DB was raised, but was not handled locally or declared in a RAISING clause
I've highlighted the relevant part.
2023 Aug 21 12:13 PM
Please edit your question and used the CODE button to format the code nicely so we can read it.
e.g.
try.
perform ztest_form_creat_sqlexception.
catch cx_sy_open_sql_db into data(err1).
l_string = | case A-1: { err1->get_text( ) }|.
catch cx_root into data(err2). " catched here<
l_string = | case A-2: { err2->get_text( ) }|.
endtry.
message l_string type 'I' display like 'E'.
try.
perform ztest_form_creat_dynexception.
catch cx_sy_send_dynpro_no_receiver into data(err3). " catched here
l_string = | case B-1: { err3->get_text( ) }|.
catch cx_root into data(err4).
l_string = | case B-2: { err4->get_text( ) }|.
endtry.
message l_string type 'I' display like 'E'.
return. " exit. " Use RETURN rather than EXIT
form ztest_form_creat_sqlexception.
raise exception type cx_sy_open_sql_db.
endform.
form ztest_form_creat_dynexception.
raise exception type cx_sy_send_dynpro_no_receiver.
endform.
2023 Aug 21 12:22 PM
You need to use raising for non-dynamic exceptions.
form ztest_form_creat_sqlexception raising cx_sy_open_sql_db.
When you run your original program the error message actually tells you this.
case A-2: An exception with the type CX_SY_OPEN_SQL_DB was raised, but was not handled locally or declared in a RAISING clause
I've highlighted the relevant part.
2023 Aug 22 3:56 AM
Your comment was really helpful.
I finally reached The New Exception Handling Concept in ABAP – Part 5,
which gave me the concept of cx_static_check, cx_dynamic_check, cx_no_check.Thanks.2023 Aug 22 5:15 AM
x_xo_o0_0 Just to be clear for future visitors, these are the parent types of cx_sy_open_sql_db and cx_sy_send_dynpro_no_receiver (respectively cx_dynamic_check and cx_no_check), hence the result you have observed are as expected.
2023 Aug 21 12:23 PM
"Catch a dump" is meaningless. You don't catch a dump. A dump is the result of not catching an exception (or of an exception which is not catchable).
2023 Aug 21 12:28 PM
2023 Aug 22 3:46 AM
2023 Aug 22 3:58 AM