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: 

How to modify constructor of custom exception class

Former Member
0 Kudos

Hello experts,

I have created a custom exception class that should perform a specific task at instantiation. So I wanted to change the default constructor that has been automatically created for this class. However, as the SAP system tells me, I am not allowed to change the construtor of a custom exception class.

So I ask myself, what do do, any way of forcing to change the constructor?

Or, alternatively, another way of automatically performing a task at ínstantiation of this exception class?

Thanks in advance for your help.

Kind regards, Matthis

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Matthias,

I have created a custom exception class that should perform a specific task at instantiation. So I wanted to change the default constructor that has been automatically created for this class.

What specific task do you want to perform? Can you be a lil' bit more specific?

BR,

Suhas

6 REPLIES 6

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Matthias,

I have created a custom exception class that should perform a specific task at instantiation. So I wanted to change the default constructor that has been automatically created for this class.

What specific task do you want to perform? Can you be a lil' bit more specific?

BR,

Suhas

Former Member
0 Kudos

I need to call a specific Z-function with some details regarding the error that caused the exception. In Java I would simply override the exception class constructor of my custom exception and call the external function from there. But how to do so in ABAP OO?

0 Kudos

Hello Matthias,

you should use the enhancement options.

Go into the constructor-code, press Ctrl-F4 ( Enhance ). With Edit->Show implicit enhancement options you see, where you can post your own code.

Kind regards,

Hendrik

Former Member
0 Kudos

great, thanks!

0 Kudos

I need to call a specific Z-function with some details regarding the error that caused the exception. In Java I would simply override the exception class constructor of my custom exception and call the external function from there. But how to do so in ABAP OO?

Hello Matthias,

I understand that we cannot change the CONSTRUCTOR of the exception class since it is generated automatically when activating the exception class.

As an alternative you can create a (instance, public) method which will call the Z-FM. And call this method when the exception is raised:

DATA: lcx_test TYPE REF TO zcx_test.

TRY .
* [try block]
CATCH zcx_test INTO lcx_test.
  lcx_test->call_z_fm( ). "Call the FM when the exception is raised
ENDTRY.

BR,

Suhas

PS: Which ABAP release are you working on?

Former Member
0 Kudos

Hi Suhas,

sure, I could simply call the external function as soon as the exception is thrown.

However, I like the OO idea of having objects doing their stuff on their own, so that I don't have to think

Cheers