Each Slice exception is mapped to a Java class with the same name. For each data member, the corresponding class contains a public data member. (Obviously, because
BadTimeVal and
BadZoneName do not have members, the generated classes for these exceptions also do not have members.) Refer to
Section 10.16.3 for additional information on data members.
Each exception also defines the ice_name member function, which returns the name of the exception.
All user exceptions are derived from the base class Ice.UserException. This allows you to catch all user exceptions generically by installing a handler for
Ice.UserException.
Ice.UserException, in turn, derives from
java.lang.Exception.
Ice.UserException implements a
clone method that is inherited by its derived exceptions, so you can make memberwise shallow copies of exceptions.
Note that the generated exception classes contain other member functions that are not shown. However, those member functions are internal to the Java mapping and are not meant to be called by application code.
Exceptions have a default constructor that default-constructs each data member. This means members of primitive type are initialized to the equivalent of zero, and members of reference type are initialized to null. Note that applications must always explicitly initialize members of structure and enumerated types because the Ice run time does not accept null as a legal value for these types.
If you wish to ensure that data members of primitive and enumerated types are initialized to specific values, you can declare default values in your Slice definition (see
Section 4.10.2). The default constructor initializes each of these data members to its declared value.
Exceptions also have a second constructor that has one parameter for each data member. This allows you to construct and initialize a class instance in a single statement (instead of first having to construct the instance and then assigning to its members). For derived exceptions, this constructor accepts one argument for each base exception member, plus one argument for each derived exception member, in base-to-derived order.