SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

ABAP Try Catch for exception is neither caught Code Inspector Error


During SAP Code Inspector result check, "The exception is neither caught nor is it declared in the RAISING clause" errors are listed with Message G-Q internal message code in my ABAP function module.

Below is a sample Code Inspector error listed for not caught exceptions in ABAP. The CX_SWF_CNT_ELEM_NOT_FOUND is not caught while calling a method of an ABAP class, and the Code Inspector is warning the ABAP programmer to catch the exception within the main program using TRY CATCH structure.

exception is neither caught nor is it declared in the RAISING clause
Code Inspector Check result: The exception is neither caught nor is it declared in the RAISING clause

Here is the sample ABAP code resulting in Code Inspector error

DATA lh_container TYPE REF TO if_swf_cnt_container.
...
lh_container->element_set(
EXPORTING
 name = swfco_manually_result_const
 value = ls_result_manually ).
Code

In order to correct such ABAP SCI, SAP Code Inspector errors, programmers can call class methods using ABAP TRY ... CATCH ... blocks as follows.

TRY .

 lh_container->element_set(
 EXPORTING
  name = swfco_manually_result_const
  value = ls_result_manually ).
CATCH cx_swf_cnt_elem_not_found.

ENDTRY.
Code

As ABAP programmers can realize at first look, on the CATCH part of the ABAP TRY-CATCH block, the exception cx_swf_cnt_elem_not_found is caught this time.

But in general, ABAP programmers can declare more than one exception for a method call.
In this case, it is a question how to know the exception names and catch all exceptions of an ABAP class method call in TRY-CATCH syntax.

Just double click on the method name, in our sample case on "element_set"
If the method signature is hidden, display it using the Signature button on top.

hide/show signature

When the signature of the class method is displayed; input parameters, output parameters and the exceptions are listed as follows.

ABAP exceptions for class methods

ABAP programmers can now copy all the exception names and add in CATCH block as follows.

TRY .

 lh_container->element_set(
 EXPORTING
  name = swfco_manually_result_const
  value = ls_result_manually ).
CATCH: cx_swf_cnt_cont_access_denied,
 cx_swf_cnt_elem_not_found,
 cx_swf_cnt_elem_access_denied,
 cx_swf_cnt_elem_type_conflict,
 cx_swf_cnt_unit_type_conflict,
 cx_swf_cnt_elem_def_invalid,
 cx_swf_cnt_invalid_qname,
 cx_swf_cnt_container.
ENDTRY.
Code

ABAP Try Catch for multiple exceptions
ABAP Try Catch syntax for multiple exceptions in a SAP class method call

After ABAP programmers modify their class method execution codes, if they re-run SAP Code Inspector following "exception not caught" error messages will be removed from the SCI result list:
The exception cx_swf_cnt_elem_not_found is neither caught nor is it declared in the RAISING clause



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.