Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exceptions in COM

Tags:

c++

exception

com

I'm writing an interface with COM code and I know that the only user of this interface is my own code (indirectly). If I throw an exception, can I catch it on the other side of the library that's in the middle? This is a termination condition so the world's most graceful cleanup isn't the biggest deal ever.

like image 552
Puppy Avatar asked Oct 28 '25 16:10

Puppy


1 Answers

Exceptions aren't allowed to flow across a COM interface boundary. Because there is no binary contract for C++ exceptions, COM cannot marshal them from one thread to another. This might not be a huge issue now but it may be a problem later on if you decide to change the threading model of your COM object.

Also, what happens if you decide that you want to rewrite the front end of your application in C# (or Delphi or whatever)? COM HRESULTS are understood by the various COM interop frameworks but C++ exceptions aren't (no binary contract for C++ exceptions).

like image 157
ReinstateMonica Larry Osterman Avatar answered Oct 31 '25 05:10

ReinstateMonica Larry Osterman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!