COM Exceptions

You would not expect an exception here. One of the core principles behind COM is that exceptions cannot cross COM method boundaries. Here, unlike the unmanaged exceptions of the previous section, no exceptions are thrown in unmanaged code. Where are the exceptions coming from? As you saw in Chapter 8, “Using COM/COM+ in Managed Code,” to call a COM component in managed code, a wrapper must be constructed to form an interop layer between the managed code and unmanaged code. As far as exceptions are concerned, the returned HRESULT from the COM method is turned into an exception by this interop layer. This translation is not unlike that which was occurring when code was imported like this:

#import "msxml3.dll"

When the compiler ...

Get .NET Common Language Runtime Unleashed 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.