Unhandled Exception caught during assignement
-
Wednesday, July 04, 2012 11:30 AM
Hi ther,
I have provided COM component to application. Application is getting an Interface pointer from the component. Application is assigning received interface pointer to the local smart pointer. Now, Application is claiming that during assignment sometimes unknown exception is caught. I have checked for the reference counts for the interface on component side and was able to confirm that the reference count is not reaching to zero. What are the possible reasons for this unknown exception being caught.
Note: Occurrence of this is rare.
The possibilities which I could think of are,
1) Interface pointer received from the component is corrupted, which I have verified. But this does not seems to be the case.
Dhanyawaad (Thanks)
2) Smart pointers are not properly implemented by application.
3) There may be exception in some other part of the code causing to this exception. (Is this possible?)
- Edited by Optimus22 Wednesday, July 04, 2012 11:31 AM
All Replies
-
Friday, July 06, 2012 5:42 AM
could you please share the erroe message?
it would be better if you could find out where the exception occur.
It is also beneficial if you can share your codes here.
Please mark this reply as answer if it helps you! Thanks for your cooperation! Good Luck to you.
-
Friday, July 06, 2012 11:10 PM
Try following
try { //Do your Smart pointer creation here } catch (_com_error &e) { OutputDebugString( e.Description()); }For more info see below link
Thanks, Renjith V R
- Edited by Renjith V RamachandranMicrosoft Community Contributor Friday, July 06, 2012 11:14 PM
- Marked As Answer by Helen ZhaoModerator Thursday, July 12, 2012 2:21 AM
- Unmarked As Answer by Optimus22 Thursday, August 02, 2012 12:00 PM
-
Thursday, August 02, 2012 12:07 PM
Hi Renjith,
I will surely try out your advice, but mean while, I would like to elaborate the problem,
I have a COM component, which passes the pointer to the application through event sink. Application is using a smart pointer. What is happening is when the application is trying to assign pointer passed by COM component, to its own local pointer, exception occurs.
I went through the smart pointer implementation (they have not implemented their own).Smart Pointer implementation provided by the COM.
template<> _com_ptr_t& operator=(Interface* pInterface) throw() { if (m_pInterface != pInterface) { Interface* pOldInterface = m_pInterface; m_pInterface = pInterface; _AddRef(); if (pOldInterface != NULL) { pOldInterface->Release(); } } return *this; }I am suspecting three possibilities for exception to occur,
1) when AddRef called on myPtr (_AddRef())
2) when Release is called on oldPtr (pOldInterface->Release())
3) Heap corruption
Of which AddRef is less likely to be cause of an exception, because, before assignment new pointer is actually passed to the function where exception occurs, so I guess while passing the parameter, copy constructor will be called and, the pointer will be AddRefed (As this is successful one, another AddRef() should not cause problem, also application claims that they are able to retrieved the values of the new pointer after exception is handled.). I suspect that Release is causing exception to occur.The heap corruption can be the cause of the exception as well.
Release may cause problem if the object has been already deleted. The object will be only deleted when the reference count reaches to zero. I have checked COM component code and can confirm that there is no release that will result in reference count reaching zero for that particular object. Application has also checked their code, and they can confirm that they are not calling an extra Release as the it is done by smart pointer implementation provided by COM itself.
Application is multi-threaded. COM component is initialized as Single thread Apartment, so I guess AddRef() an Release() call must be serialized.
My Queries are
1) Can there be mismatch of reference count, for example it is reaching to zero (one AddRef did not have its effect) when it should have been 1. Does reference counting is dependent on processor type, because the Issue is observed on customized processor and the occurrence of the Issue is rare.
2) Can Heap Corruption result into this kind of behavior?
One more thing I need know is, currently application has implemented catch block with ellipsis(...), and hence the details of the exception are unknown. Can anybody point me to some reference, with help of which application can improve the exception handling in order to know the exact description of the exception.Dhanyawaad (Thanks)
-
Thursday, August 02, 2012 7:05 PM
1) Can there be mismatch of reference count, for example it is reaching to zero (one AddRef did not have its effect) when it should have been 1. Does reference counting is dependent on processor type, because the Issue is observed on customized processor and the occurrence of the Issue is rare.
As per my understanding _AddRef() did not have any dependency to the Processor. It automatically increments a count during each interface creation. Also Release() decrements this count.
One more thing I need know is, currently application has implemented catch block with ellipsis(...), and hence the details of the exception are unknown. Can anybody point me to some reference, with help of which application can improve the exception handling in order to know the exact description of the exception.
Have you implemented catch block as follows
Refer previous post for _com_error methods. I think this error will catch by _com_errorcatch(_com_error &e) { } catch(...) {
}
Thanks, Renjith V R
- Marked As Answer by Optimus22 Monday, November 05, 2012 9:53 AM
-
Friday, August 03, 2012 10:44 AM
Yes,
Had implemented the com_error block, but the catch block is ellipsis is executed instead, so it is kind of unknown exception.
Dhanyawaad (Thanks)
-
Friday, August 03, 2012 5:37 PMSince you got exception before the interface pointer return, exception is probably related to your COM server implementation. You should check the event log also. You can find the exact exception function by putting break point in your catch block and check call stack.
Thanks, Renjith V R
-
Monday, August 06, 2012 5:56 AM
COM server has already returned the pointer to the application. After which application passes the pointer, to some local function, in which the assignment is happening. One more thing, as I noted the pointer returned by COM server is the healthy one, we can confirm that. As I mentioned earlier the exception may occur due to to release of the old pointer stored locally.
Which logs are u talking about, I am not aware of this, can u guide me on this?
As you mentioned, Debugging would certainly help, but the occurrence of Issue is very rare. We will be lucky if we can reproduce it :D
Dhanyawaad(Thanks).
-
Monday, August 06, 2012 1:23 PMI am telling about eventlogs. But it seems some imple,mentation error not COM error. So eventlog wont help. Can you post the your local function and its call.
Thanks, Renjith V R
-
Wednesday, August 08, 2012 6:34 AM
I did't get you. Are you asking for code snippets?
One query, Can heap corruption cause this exception to occur?
Dhanyawaad (Thanks).
-
Wednesday, August 08, 2012 8:57 AM
Yes i am asking code snippets of your local function implementaion. And i hope you are passing a valid interface pointer to that function
One query, Can heap corruption cause this exception to occur?
As per my understanding, heap corruptions in smart pointer causes exception.
Thanks, Renjith V R
-
Tuesday, August 28, 2012 6:28 AM
Hi Renjith,
Sorry, that I could not share the code with you.
I have received the dump for the exception. How can I analyze the dump for any heap corruption. Can you point out me to a tutorial for this?
Dhanyawaad (Thanks)

