Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

OO help retrieving exception object

abap1opti
Discoverer

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?

1 ACCEPTED SOLUTION

Tomas_Buryanek
Active Contributor

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.
-- Tomas --
7 REPLIES 7

former_member184158
Active Contributor
0 Kudos

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.

abap1opti
Discoverer

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?

FredericGirod
Active Contributor
0 Kudos

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

Tomas_Buryanek
Active Contributor

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.
-- Tomas --

0 Kudos

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:

0 Kudos

abap1opti :

  • Yes for deeper chain it would continue "...->PREVIOUS->PREVIOUS->PREVIOUS..." 🙂
    There might be more levels than two (theoretically unlimited hmm?) but I have never seen it.
  • Yes PREVIOUS attribute is inherited from CX_ROOT.
-- Tomas --

0 Kudos

Perfect. Thanks for all the info.