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 ...

Get Using XML with Legacy Business Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.