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: 

ABAP OO Exception Class based processing

Former Member
0 Kudos

Hi there,

Note: In going forward with SAP WAS 6.20, one can handle exceptions using exception-class based handling using RAISE EXCEPTION TYPE abc and then CATCHing it in TRY/ ENDTRY block. Standard method like GET_TEXT can be used to get the text of the exception raised.

Question: If I know the EXCEPTION CLASS and Exception ID of my exception class, is it possible to get the exception text directly from the repository without creating the exception class object?

E.g. Exception class is CX_MY_SECRET_ID

and Exception IDs for this class are

ID_NOT_FOUND,

ID_EXPIRED,

ID_IS_FOR_SPECIAL_ACCESS

E.g. last two exception IDs are my warning conditions, and if such conditions are encountered, all I want to do is collect the warning messages. Whereas first exception ID condition (i.e. ID_NOT_FOUND) is an error for me, in which I have pass the exception back to the calling program. E.g. the source code is like this:

PERFORM.......

If ID is not found

RAISE EXCEPTION TYPE ZCX_MY_SECRET_ID

EXPORTING TEXT_ID = 'ID_NOT_FOUND'.

else if ID has expired

...... then do I have to first raise the exception like raised above and CATCH it before I can get its text? or can I get the exception text directly without raising the exception first (as I know i have to retrieve the text of ZCX_MY_SECRET_ID exception class for Exception ID ID_EXPIRED)?

In other words, if a certain condition is warning for my program, can I get the condition for that exception (from exception class based on exception class name and exception ID), or do I have to RAISE it first explicitely and then CATCH it immediately and execute GET_TEXT to get its text?

Thanks very much!

1 REPLY 1

former_member183804
Active Contributor
0 Kudos

Hello Chetan,

in basic the raise exception type xxx creates an exception object and aborts normal execution continuing in the enclosing try block.

The Abap runtime contains some optimizations regarding the try block has an 'into xxx' clause. But as long you use the same exception you cant take benefit from this.

As far I understand your problem you have two different kind of severities. So I would use 2 differnt exception classes (maybe derived from a common parent type, or one from the other).

So both the code which throws the exception and the one which catches it are aware of the different semantic.

Kind Regards

Klaus