Skip to Content
author's profile photo Former Member
Former Member

Object oriented exception concept -

Hi all,

I'm trying to get familiar with the object oriented exception concept, but there's one point which I did not understand so far:

I created an exception class inheriting from class 'CX_DYNAMIC_CHECK'. In order to store additional information, I added some additional attributes to my class that should be filled when the exception is raised.

So I tried to add additional import parameters to the constructor and to fill the additional attributes within the constructor, but I'm not able to change the constructor at all, i.e. I can't add additional import parameters nor am I able to change the source code of the constructor.

Can you give me any hint how to deal with additional attributes?

Best regards,

Markus

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Oct 25, 2010 at 08:30 PM

    In order to pass more values / parameters in the CONSTRUCTOR, you need to create them as the Attributes of the class. As soon as you create it as attribute, it would be available as the signature of the CONSTRUCTOR. E.g if you add V_MESSAGE as the attribute, system would create a importing signature V_MESSAGE of CONSTRUCTOR and also add the code to populate the attribute V_MESSAGE from importing parameter V_MESSAGE.

    method CONSTRUCTOR.
    CALL METHOD SUPER->CONSTRUCTOR
    EXPORTING
    TEXTID = TEXTID
    PREVIOUS = PREVIOUS
    .
    me->IV_MESSAGE = IV_MESSAGE .  " <<
    endmethod.
    

    You can use this to pass the value while Raising the Exception:

    RAISE EXCEPTION TYPE ZCX_TEST_NP  EXPORTING
      V_MESSAGE = 'This is test'.
    

    When you catch it, you can actually use the attribute to access the value:

      data: o_Exc type ref to zcx_test_np.
      catch zcx_test_np into o_exc.
         write: / 'Exception', o_Exc->v_message.
    

    Regards,

    Naimesh Patel

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 26, 2010 at 07:38 AM

    Thanks a lot!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.