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.
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
In order to correct such ABAP SCI, SAP Code Inspector errors, programmers can call class methods using ABAP TRY ... CATCH ... blocks as follows.
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.
When the signature of the class method is displayed; input parameters, output parameters and the exceptions are listed as follows.
ABAP programmers can now copy all the exception names and add in CATCH block as follows.
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