Exceptions
In keeping with C++ best practices, the Internationalization Module throws exceptions in error situations. Most Internationalization Module classes throw exceptions of type
RWUException.
A few classes in the Internationalization Module throws exceptions other than
RWUException:
RWUException derives from the
RWxmsg class defined in the Essential Tools Module. The inherited
why() method returns a textual description of the error. For example:
try {
// Do something here
} catch (RWUException except) {
std::cout << except.why() << std::endl;
}
Instances of
RWUException also contain a status code. The global enumeration
RWUStatusCode identifies the type of the error. For example, status code
RWUIndexOutOfBoundsError indicates that an array index was out of bounds. Status codes help you pinpoint the exact nature of the problem. Member function
RWUException::getStatus() returns the RWUStatusCode.
Not all unusual situations warrant exceptions. For example,
RWUResourceBundle::getStatus() returns an
RWUStatusCode indicating whether the bundle contains data retrieved from an exact match for the requested locale, from a fallback match, or from the root bundle. (See
Chapter 10.) Although you may want to know that fallback has occurred, this is not an error condition. The fallback mechanism ensures that whenever possible some value for a resource is always found, since there should be some value for every resource in the root bundle.
Similarly, a variety of errors can occur in the conversion process, but these do not warrant exceptions. For example, the character being converted may not have a representation in the target encoding, or the code units in the source string may not be interpretable as a code point value in the source encoding. Instead of throwing exceptions, the converter classes provide
setErrorResponse() methods for specifying how a converter should handle erroneous input. (See
Conversion Errors.) You could, for example, tell a converter to skip over offending sequences, or to substiute for offending sequences by appending a specific substitution sequence to the output buffer.