Creating Exception Classes
8.5.5 Mapping Exception Texts to Message IDs
Beginning with the release 6.40 of the SAP NetWeaver Application Server, you
can now map exception texts to message IDs within a message class. You can
enable this functionality
in
your exception classes by choosing the WITH MESSAGE
CLASS option in the CREATE CLASS dialog box (asyou've already
seen
in Figure 8.7).
To demonstrate how to map exception texts to message IDs, let's consider an
example of an exception class called ZCX_USER_CREATE_FAI LEO that is used to han-
dle exceptions related to the creation of users in a custom user management API.
1. To provide information about the user in question, a public instance attribute
called USER_NAME has been provided that will be added to the parameter inter-
face of the CONSTRUCTOR method (see Figure 8.13).
Class interface 2CX_USER_CR€ATE_FAIIE0 implemented/mac ttve
Properties interfaces Fnends mi- imcs 1 Teas Metnods Events Types Aliases
Eflra Misers i si cam
• filter
|Aar.&uee |Levei Ivisi |Re Imping |AssooatedType
Description initial value
IF_TtOO_HESSA6E-OEFAlCo«iStanPuWic
*
I F_T 100_N£SSA6E-T
1
MHnstanctPuMK Type SCX_T160KEY
T100 Key wrtti Parameters
CX.ROOT ConstanPubiK Type SOTR.COMC
Excepfcon© value fw Afirri6AA9A3937
TEXTIO instancePubiic F Type
SOTR.COMC
Key for Access io Message
PREVIOUS instancePubix F Type fief
CX_ROOT
<•
Exception Mapped to the C
KERKEl.ERfilO instancePubtx F Type
S380ERftIC- O
internal Nam® of EwepOor
C0_0UPL
1
CATE_0SER ConsianPubhc T Type SOTR_COKC
tfSER_NAHE| instancePubW • Type SYUHAHE
O
Jser Name
• Type
O
Figure 8.13 Defining Parameters in ZCX_USER_CREATE_FAILED
2. If you look carefully on the INTERFACES tab of the Exception Builder, you will
notice that this exception class is implementing interface IF_T100_MESSAGE.
IF_T100_MESSAGE is a nested interface that embeds the I F_MESSAGE interface
that you have normally
seen
used with exception classes. The I F_TI00_HESSAGE
interface also defines some attributes that support the mapping of exception
texts to message IDs. These details are encapsulated inside the implementations
of methods IF_MESSAGE~GET_TEXT and IF_MESSAGE~GET_LONGTEXT in the root
exception class CX_R00T.
3. To map an exception text to a message ID, you can simply create a new excep-
tion text and click on the MESSAGE TEXT button in the toolbar above the excep-
tion text input table. This will bring up the ASSIGN ATTRIBUTES OF AN EXCEPTION
22 7