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, and also contains the row number and column number where the error occurred in the 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 and the line number and column number at which the method detected the error. The HydraExpress exception hierarchy derives from rwsf::Exception, so the block catches RWxmsg as well as std::exception.
try { aComplexType.unmarshal(xmlContents); } catch (const rwsf::XmlParseError &e) { std::cerr << "Parse error when unmarshaling : " << e.what() << std::endl; std::cerr << "Line number: " << e.getLineNumber() << std::endl; std::cerr << "Column number: " << e.getColumnNumber() << 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;
}
©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.