Technical Articles
How to retrieve the root exception when receiving the error message “An exception was raised (Message No. SY530)”
When developing sample code it often happens that an underlying framework raises an exception that was not caught by the API itself that I have called in my code.
As a result you only get an unspecific error messages such as
An exception was raised (Message No. SY530)
If you are working on SAP NetWeaver 753 or later (that means SAP S/4HANA 1809) on premise or SAP Cloud Platform ABAP Environment there is a new method available as pointed out by Dominik Bigl (see his valuable comment below).
For older releases you can use a small method get_root_exception that I usually add to my test classes so that I get the longtext of the exception that was originally called and that caused the issue.
CLASS zcl_get_root_exception DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS get_root_exception
IMPORTING
!ix_exception TYPE REF TO cx_root
RETURNING
VALUE(rx_root) TYPE REF TO cx_root .
ENDCLASS.
CLASS zcl_get_root_exception IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
TRY.
DATA num1 TYPE i VALUE 2.
DATA num2 TYPE i VALUE 0.
DATA(result) = Num1 / Num2.
out->write( result ).
CATCH cx_root INTO DATA(lx_exception).
out->write( 'root exception: ' && get_root_exception( lx_exception )->get_longtext( ) ).
ENDTRY.
ENDMETHOD.
METHOD get_root_exception.
rx_root = ix_exception.
WHILE rx_root->previous IS BOUND.
rx_root ?= rx_root->previous.
ENDWHILE.
ENDMETHOD.
ENDCLASS.
Hi
With 753 there is also a new method for IF_T100_MESSAGE exceptions to get the first NON SY530 exception object:
regards
Domi
Thanks for the update.
I was not aware of this.
See also your http://www.cadaxo.com/contentwp/wp-content/uploads/2020/03/Webinar-ABAP-7.53-7.54.pdf
and the online documentation
https://help.sap.com/doc/abapdocu_753_index_htm/7.53/en-US/abennews-753-exceptions.htm
Will save me to write these lines in newer releases :-).
Only now saw the typo in the title ?.