When my application crashed, I want to get the crash infomatin from the user,so i wander how to get the crash info from the user?And how to handle the exceptions when the main application crashed?
ps.Just like that window:"Would you like to send the crash info to Microsoft?"
Asked
Active
Viewed 110 times
1

magicshui
- 979
- 3
- 11
- 23
1 Answers
2
What you need to do is catch all uncaught exceptions for the application.
The AppDomain.CurrentDomain.UnhandledException
event handler allows you to add an event handler for all uncaught exceptions. With the exception you receive with this event, you can show the dialog you want.
See articles like Why is .NET exception not caught by try/catch block? on how to catch all exceptions.

Community
- 1
- 1

Pieter van Ginkel
- 29,160
- 8
- 71
- 111
-
"Oh my god!", that was my first thought when I read your first sentence. What you're looking for is (as mentioned) the `AppDomain.CurrentDomain.UnhandledException`, wire a handler to it, and you can catch **every** exception in your application. Also wire a handler against `Application.ThreadException` and you get every exception from another thread...on second thought, your link does describe this very good, no need for encapsulating everything into `Try { ... } catch`. – Bobby Nov 22 '10 at 07:54
-
You're right. Wording may not be perfect. What I mean by the try/catch is the mechanism used by `AppDomain.CurrentDomain.UnhandledException`. I'll rewrite my answer. Thanks. – Pieter van Ginkel Nov 22 '10 at 07:57
-
@Pieter: I thought that it was just ill-stated, but wasn't sure, though. Anyway +1. – Bobby Nov 22 '10 at 11:46
-
-1. Not all exceptions can be captured on managed side, typically low level .NET errors. – Lex Li Nov 23 '10 at 12:59
-
@Lex Li - You mean like a `StackOverflowException`? Yep, you're right, they can't be caught. Have a suggestion? Would be happy to update the answer. – Pieter van Ginkel Nov 23 '10 at 15:30
-
Microsoft itself offers WER, http://www.microsoft.com/whdc/winlogo/maintain/StartWER.mspx. Besides, prepare a guidance to your end users on how to capture crash dumps, http://support.microsoft.com/kb/931370, if you don't want to use Microsoft service. Third party crash reporter is also an option, http://en.wikipedia.org/wiki/Crash_reporter – Lex Li Nov 27 '10 at 02:52