MadBoy
MadBoy

Reputation: 11104

Visual Studio 2010 UnhandledException, ThreadException error handling?

In my code I had an error that was catched by following exceptions while program was running. However when I was running program in Visual Studio when the error was happening application was simply exiting without any error (other errors usually bring me to the problematic line).

if (ApplicationDeployment.IsNetworkDeployed) {
    AppDomain.CurrentDomain.UnhandledException += currentDomainUnhandledException;
    Application.ThreadException += applicationThreadException;
}

Of course if i remove the if i get this exception handling done by my methods which simply uses MessageBox to show the error. Is there a way to force Visual Studio to catch this error like it catches other types of errors?

Upvotes: 0

Views: 640

Answers (1)

Hans Passant
Hans Passant

Reputation: 942197

Only by using Debug + Exceptions, Thrown checkbox. That makes the debugger stop on the "first chance". At the point the exception is thrown. You typically want to do this:

        if (!System.Diagnostics.Debugger.IsAttached) {
            // Subscribe the events
            //...
        }

Note that this already works that way for Application.ThreadException, Winforms already avoids catching exceptions if it sees a debugger. For the exact same reason.

Upvotes: 2

Related Questions