Solved

COM event handler does not raise Exceptions that terminate the application

Posted on 2008-10-02
1
248 Views
Last Modified: 2013-12-17
I have an VB.Net application that has to use a COM object. That COM has an object that raises events that I process.

If inside the eventhandler I make a Throw New Exception() (or an Exception happens) the eventhandler exists (that's the expected behaviour) but nothing more happens. No unhandled exception eventhandlers catch the exception not the application ends with the tipical Unexpected Exception.

The Debuger shows that the COM eventhandler is executing at the main thread if this helps.

As an example you see this code. Executing this produces no result at all, its like it has not been executed
Private Sub DataChange(ByVal eventIdentifier As Integer, ByVal itemsChanged As Integer, ByRef clientHandlesArray As System.Array, ByRef valuesArray As System.Array, ByRef qualities As System.Array, ByRef timeStamps As System.Array) Handles m_mainGroup.DataChange

    Dim index As Integer

 

    Throw New Exception() ' To see what happens

    For index = 1 To itemsChanged

        Me.OnItemChanged(m_itemListByHandler.Item(DirectCast(clientHandlesArray.GetValue(index), Integer)).ItemID, valuesArray.GetValue(index))

    Next

End Sub

Open in new window

0
Comment
Question by:Ignacio Soler Garcia
1 Comment
 
LVL 5

Accepted Solution

by:
Ignacio Soler Garcia earned 0 total points
ID: 22768496
The solution to this question is explained here

http://www.codinghorror.com/blog/archives/000216.html

Exceptions rised in threads created outside the CLR are ignored.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now