There exist two kinds of exception handling in ABAP OO – The classical one and the object orientated one.
The classical one is similar to exception handling used by function modules: We can raise an exception together with a message (using ABAP statement „message … raising“). The caller need to catch and to handle this exception.
The object orientated exception solution (raised using the ABAP statement „RAISE EXCEPTION TYPE „) has the important positive issue that the caller doesn’t need to handle the exception. If the caller is not able or willing to handle the exception, it will be propagated to the caller of the caller automatically.
However, the object orientated exception is more complicated in cases we just want to throw an error message because we need to create an exception class first.
Good News: This is very simple.
- We can use or inherit from exception class CX_T100_MSG if we know message id and number at runtime only and these information are available in variables like SY-MSGID, SY-MAGNO, SY-SMG-TY, SY-MSGVX.
- We can use or inherit from class CX_RSR_BAPIRET2 if we have message information available in a BAPIRET2 structure used by many BAPI function modules. Since CX_RSR_BAPIRET2 is final, we cannot inherit from it. Therefore we once need to create a copy first.
- If we know message id and numbers (can be several!) at design time but message parameters only at run time, we can create an exception class based on interface IF_T100_MESSAGE (or simply flag „With Message Class“ at creation). For details, we can use the following guides:
http://freesapabap.blogspot.fr/2014/12/oo-abap-exception-using-message-class.html
http://zevolving.com/2013/04/exception-class-to-use-messages-from-t100/