Exceptions and Errors

Well-behaved COM server objects don't usually throw exceptions back to their clients , but they can. So, to be cautious it's a good idea to put most of your COM- related code in a try block and follow it with a catch block for COM errors. COM errors are encapsulated in the Visual C++ compiler helper class _com_error.

Other than that, you need to know about HRESULT. This is a 32-bit data structure used to return status information about calls to methods in the COM APIs. You can't just check on a nonzero return value to see whether or not a call failed; it is a more complex data structure than that. Visual C++ provides some macros to check on HRESULT. I use FAILED and SUCCEEDED. Both return booleans. You'll see that the book's code also checks on some more specific return values associated with the MSXML DOM implementation.

If you want to do by-the-book COM programming, you will check for the HRESULT return from every method call to a COM interface. We could do this, but the code would be littered with status checks that in 99.9 percent of the cases would never execute the failure branch. I instead rely primarily on schema validation to enforce some expectations about the input XML documents we'll be processing and check for NULL pointers where applicable .

Using XML with Legacy Business Applications
Using XML with Legacy Business Applications
ISBN: 0321154940
EAN: 2147483647
Year: 2003
Pages: 181

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net