Restart
Restart

Reputation: 57

Why two different results while handling the same Exception in C#?

I handled the same exception in two programs, but I got the different results. I don't know why.

the first result is the one the program unable to caught

Scapshot1:      www.freeimagehosting.net/uploads/e2b37433a3.png

and the second is the one the program succeed to caught

Scapshot2:      www.freeimagehosting.net/uploads/6ab7564999.png

Why I got such a different?

Upvotes: 0

Views: 148

Answers (5)

Hans Passant
Hans Passant

Reputation: 941327

You cannot change Application.UnhandledExceptionMode after Application.Run() was called, so clearly that's not the one that's going to catch the exception.

Which leaves AppDomain.UnhandledException. Yes, the debugger will break on the exception before that event is raised. Nice feature, allows you to debug the exception reason. Just press F5 to continue execution to trigger the event handler. There's no evidence of you using the debugger in the 2nd screen shot, looks like you started it with Ctrl+F5.

Upvotes: 1

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239646

The behaviour of the debugger in the face of exceptions can vary wildly.

Exception Handling (Debugging)

Upvotes: 1

tom3k
tom3k

Reputation: 106

I am not sure if I understand, it looks like it's the same erro but

  • pic1 - unhandled error
  • pic2 - handled error

please provide more information

Upvotes: 1

leppie
leppie

Reputation: 117220

From what I can see, in #1 you are running in the debugger. In #2 you are not.

In fact, I will assume the exception is exactly the same, as the message is the same. There is no difference, IOW.

Upvotes: 3

Jon Skeet
Jon Skeet

Reputation: 1500145

Well, you haven't really provided much context. Things to check:

  • Are they the same type of application (WPF, WinForms, Silverlight, Console etc)?
  • Are they using the same version of .NET?
  • Are they running on the same version of Windows?
  • Do they have the same code for reacting to unhandled exceptions?

Upvotes: 3

Related Questions