tags:

views:

70

answers:

1

I encountered an exception in our application that isn't handled at all. I really don't know what to look for to debug this problem since the application close immediately when this peculiar exception is thrown (even running from VS). The exception handling is setup that way:

[STAThread]
[LoaderOptimizationAttribute(LoaderOptimization.MultiDomainHost)]
static void Main()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ApplicationExit += new EventHandler(ApplicationExitHandler);
Application.ThreadException += new ThreadExceptionEventHandler(ThreadExceptionHandler);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
...

The thread from which the exception is thrown is started that way:

Thread executerThread = new Thread(new ThreadStart(modele.Exporter));
executerThread.SetApartmentState(ApartmentState.STA);
executerThread.Start();

Now, every unhandled exception thrown from that thread fire up our UnhandledExceptionHandler except the one I have problems with. Even if I catch the problematic exception and throw it again, the application closes silently. None of the 3 handlers (ApplicationExit, ThreadException, UnhandledException) get fired (breakpoints not hit).

There is nothing so exceptional in that exception (see details here: http://pastebin.com/fCnDRRiJ).

+1  A: 

You are working with OleDb provider which has calls to native code. If native code fails with some type of exceptions CLR can close the process silently. I've had common probles with OleDb provider for Sybase, I believe only some workarounds can help you, not a specific solution.

Andrew Bezzub
You are almost surely correct. The best I can do is to catch to handle the exception directly in the thread. That mean we cannot trust AppDomain.CurrentDomain.UnhandledException to log everything.
Simon T.
I still find it odd that if I catch the exception the application keeps working just fine. It's like if there was some flag set somewhere that says "Next time you get an unhandled exception, just close". It doesn't make much sense.
Simon T.