I'm trying to find information on if the IDispatch
interface throws, specifically if IDispatch::GetTypeInfo()
does. IIRC, IDispatch::Invoke()
can, but I can't seem to find anything on the subject and the documentation here or here doesn't mention anything about this.
Asked
Active
Viewed 345 times
0

Adrian
- 10,246
- 4
- 44
- 110
-
@NeilButterworth, according to the links that I posted, it's part of ATL. – Adrian Aug 01 '18 at 22:12
-
`IDispatch::Invoke()` cannot throw either. If it invokes a function of some object and that function tries to throw across a COM boundary it's undefined behaviour (COM functions should not leak exceptions) – M.M Aug 01 '18 at 22:19
-
Easy answer, COM interfaces are never allowed to throw. Exception handling is impossible to do correctly across language runtime boundaries. One basic reason that every IDispatch interface method **must** return an HRESULT, "it didn't work" is the most important detail. Language bindings are free to turn the HRESULT into an exception, they routinely do so. Even in C++ when you use the #import directive. Fwiw, having to squeeze the failure of a complicated library function into a single error code is the primary reason why COM+ lost the middleware war to Java and why UWP is having trouble. – Hans Passant Aug 01 '18 at 22:20
1 Answers
3
None of the standard COM interfaces will throw. COM was designed to be language agnostic, including languages that don't have exceptions.
It's entirely possible that the implementation of a COM object might throw, but that's up to the implementation of the object itself. Normally a COM object will indicate an error by returning an error code for its HRESULT.

Mark Ransom
- 299,747
- 42
- 398
- 622
-
`IDispatch` is a C++ wrapper for the COM interface, so I figured that it would implement a throwing mechanism. – Adrian Aug 01 '18 at 22:15
-
@RemyLebeau, ah, I thought that was weird. Yes, I'm looking at `OAld.h` which is part of `Windows Kits` (`c:\Program Files (x86)\Windows Kits\8.1\Include\um\OAIdl.h`), which I'm assuming is part of the VS install. I'm guessing that MS didn't do anything wild and make it throw as that would prolly be confusing to C/C++ devs. – Adrian Aug 01 '18 at 22:21
-
2`IDispatch` itself is NOT a C++ wrapper, it is just another COM interface like any other. You are likely using a C++ wrapper that **implements** `IDispatch`, but that is a separate issue. COM implementations are not allowed to throw. But wrappers that *consume* COM interfaces MAY throw when they detect COM errors being reported (see the [`_com_error`](https://msdn.microsoft.com/en-us/library/0ye3k36s.aspx) class in ATL, the [`COMException`](https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comexception(v=vs.110).aspx) class in .NET, etc) – Remy Lebeau Aug 01 '18 at 22:21