Click here to Skip to main content
14,933,981 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have an out of proc COM server implemented in an exe. one of the COM method raise an exception instead of returning an HRESULT

ex:
HRESULT ComObject::Fubar()
{
RaiseException(1,0,0,0,NULL);
return S_OK;
}

in my client, after calling Fubar(), sometime the HRESULT is positive, sometime it is negative. When the value is positive I seem to be able to call the COM object again, can I trust this, or am I in undefined land ?

How does the COM plumming handle uncaught exception ?

I am not in charge of the COM server throwing the exception, I am the client. The company writting the server will not change it (it is old technology). My boss wants me to have my client behave correctly even after the server threw an exception, in a nutshell he does not want the client app to crash because of this.
I've notice that when a OUT of PROC server throw an exception, it seems to always return the value: 0x80010105
Can I trust the COM plumbing to always return this error ? I could not find the answer on microsoft site.

thanks for any link on the subject.

Wonixen
Posted
Updated 23-Jun-10 2:58am
v2

It's illegal for a COM method to throw exceptions. The reason is simple: COM is designed to be language independent and exceptions don't fit the bill (there is no common exception mechanism shared by all languages). In fact in general C++ exceptions can't even be safely caught by a different companies C++ compiler. COM provides the IErrorInfo interface and the functions GetErrorInfo and SetErrorInfo (and the IDispatch interface is also involved) to provide something which will look like exceptions to some clients.
   
v6
Comments
Wonixen 20-Jun-10 23:02pm
   
Yes, I know, I've read Effective COM. I've read a lot on COM, I've been doing C/C++ for 24 years. BTW, did you read the text ? because I show that the method call RaiseException, it has nothing to do with C++, it is a win32 api!!! Micropoche is in charge of both the win32 API & the COM API, so maybe they do catch structured exception and return some HRESULT
Thanks
Stephen Hewitt 21-Jun-10 20:31pm
   
If you know that you're not supposed to throw exceptions from COM methods what's the problem? btw. Exceptions thrown with RaiseException are included (you're not meant to thow them).
Wonixen 23-Jun-10 8:56am
   
I am not in charge of the COM server throwing the exception, I am the client. The company writting the server will not change it (it is old technology). My Boss wants me to have my client behave correctly even after the server threw an exception, in a nutshell he does not want the client to crash because of this.
I've notice that when a OUT of PROC server throw an exception, it seems to always return the value:
0x80010105
Can I trust the COM plumbing to always return this error ? I could not find the answer on microsoft site.
Thanks
How does COM handle them? In general by crashing! In the out-of-process case the server will probably crash and the client's proxy become disconnected (all client methods will return RPC_E_DISCONNECTED). In the in-process case you'll take down the process (which contains both client and server). COM provides no mechanism to marshal the exception across to the client (there's no mechanism to marshal exceptions to across apartments, be they in the same or a different process).
 
Your comment to my previous post sounds a little defensive. I'm not questioning your experience (I've got no way of knowing this one way or the other), just trying to answer your question.
   
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900