XML Binding Development Guide : PART III Advanced Topics : Chapter 8 Mapping XML Schema to C++ : Data Binding Parsing Errors
Data Binding Parsing Errors
The data binding runtime may throw an exception while unmarshaling a document. If the document is not well-formed or the document structure is invalid, the unmarshal function throws an rwsf::XmlParseException. The parse error contains a string that describes the error in the XML document. HydraExpress propagates any other exceptions thrown. In particular, note that although HydraExpress does not explicitly validate content while unmarshaling a document, the data type classes that HydraExpress uses may throw exceptions when provided with invalid input. Here are the guidelines for exception handling:
Always catch rwsf::Exception. You can catch more specific derived exceptions.
Catch std::exception if your implementation code uses standard library classes.
Catch RWxmsg if your implementation classes uses SourcePro C++ classes.
The code sample below shows a try-catch block that contains a call to unmarshal. The XML parsing error exception contains a descriptive message. The HydraExpress exception hierarchy derives from rwsf::Exception, so the block catches this exception as well.
 
try {
aComplexType.unmarshal(xmlContents);
} catch (const rwsf::XmlParseException &e) {
std::cerr << "Parse error when unmarshaling : "
<< e.what() << std::endl;
return 1;
} catch (const rwsf::Exception &e) {
std::cerr << "Error : " << e.what() << std::endl;
return 1;
} catch (const RWxmsg &e) {
std::cerr << "Error : " << e.what() << std::endl;
return 1;
} catch (const std::exception &e) {
std:: cerr << “Error : “ << e.what() << std::endl;
return 1;
}