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:
*RWUString derives from RWBasicUString in the Essential Tools Module, which throws RWConversionErr if truncated, illegal, or irregular sequences are detected during conversion to and from UTF-8. Also, RWBasicUString throws RWBoundsErr if an offset or a combined offset and length exceeds the current bounds of the string. See the entries for RWConversionErr and RWBoundsErr in the SourcePro API Reference Guide.
*RWURegularExpression throws exceptions of type RWRegexErr in response to invalid regular expression patterns. This is for consistency with the regular expression classes in the Essential Tools module. See the entry for RWRegexErr in the SourcePro API Reference Guide.
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.