02-13-2012 10:00 AM
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
02-13-2012 10:46 AM
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
02-13-2012 10:46 AM
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
02-13-2012 10:57 AM
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?
02-13-2012 11:06 AM
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
02-13-2012 11:16 AM
02-13-2012 11:43 AM
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?
02-13-2012 12:10 PM
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