2023 Mar 01 10:33 PM
I'm an OO noob - forgive me if this is an obvious question. I am calling a method - part of a class pulled down from ABAP GIT - ZCL_JSON_HANDLER) - that deserializes a JSON string (DESERIALIZE_ID). I would like to improve on the error handling. Through debugging, I can drill into the caught exception typed as CX_ROOT. How to I retrieve/reference the text shown in the diagram?
2023 Mar 02 8:02 AM
Hello,
what you see on your screenshot (where red arrow is pointing) is actually a "Chain of Exception Object".
To get the previous exception text you can access attribute "previous" like this:
IF oexcp->previous IS NOT INITIAL.
DATA(previous_exception_text) = oexcp->previous->get_text( ).
ENDIF.
2023 Mar 01 11:20 PM
Hi,
Do you want to call this method and retrieve the message, then display it? Or, what exactly is your goal? This code contains an exception, and you should try to catch it in your method.
2023 Mar 02 4:33 AM
Thanks for responding. Per the first screen shot above, the CX_ROOT exception is being caught into an object named OEXCP. What I don't know how to do is reference the details within that object as displayed in the detailed view in the debugger shown in the second screen shot. Per that image, you can see a "chain of exception objects", and the second row there shows exactly the issue. What code do I need to write to retrieve that text? Is that not contained somewhere within the caught object OEXCP?
2023 Mar 02 7:25 AM
I think you have exactly the code you are searching for in the screenshot (in blue).
you have to catch ZCX_JSON into a ref to and use the method Get_Text to have the text of the error
2023 Mar 02 8:02 AM
Hello,
what you see on your screenshot (where red arrow is pointing) is actually a "Chain of Exception Object".
To get the previous exception text you can access attribute "previous" like this:
IF oexcp->previous IS NOT INITIAL.
DATA(previous_exception_text) = oexcp->previous->get_text( ).
ENDIF.
2023 Mar 02 2:39 PM
Thanks, Tomas! That got me exactly what I was looking for. For my reference, can this "previous" nesting go deeper than 2 levels? (Assuming you know how many levels to look for.) E.g. is "oexcp->previous->previous->" valid syntax? Either way, this is simply inherent in the definition of CX_ROOT, correct?
Image of successful code:
2023 Mar 02 3:25 PM
abap1opti :
2023 Mar 02 5:37 PM