Remember most unhandled exceptions in most Windows Forms apps will be
handled by the Application.ThreadException, the AppDomain.UnhandledException
will only handle the exceptions not handled by the above handler... (at
least that is my experience).
Yes, I have bumped into something similar when working on a VS .NET add-in.
Strangely enough, the UnhandledException event didn't raise for the primary
thread the add-in was running on, while the event was raised as expected for
any other thread I had created manually. This came as a big and unpleasant
surprise, and I still haven't got any 'official' explanation. My only guess
is since VS .NET communicates with the add-in through CCW (COM-callable
wrappers), it is possible the framework silently installs its own handler
for the UnhandledException event to translate a managed exception to a COM
error (HRESULT + IErrorInfo).
As for the WinForms and ASP .NET applications, it is indeed better to use
the recommended means such as Application.ThreadException. Still, I'd add a
handler for UnhandledException too not to miss "survivors" who managed to
bypass the "first line of defense".
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
Jay B. Harlow said:
Dmitriy,
Yes its raised on all three, however it is the only one raised for console
applications, the other two are not.
My understanding of the event itself, which I admit is limited, its
usefulness in ASP.NET & Windows Form is "limited", hence my statement "for
console application". As I personally do not have a clear indication of when
you would need to include it in ASP.NET & Windows Forms, at least I cannot
really explain it. If you have something the clearly & briefly explains when
the event is raised, I would love to hear it.
Remember most unhandled exceptions in most Windows Forms apps will be
handled by the Application.ThreadException, the AppDomain.UnhandledException
will only handle the exceptions not handled by the above handler... (at
least that is my experience).
Hope this helps
Jay