So lets say I happen to have an unhandled exception in my application or it crashes for some reason. Is there some way for me to capture the output and show an error report dialog when the application crashes.
What I'm thinking is having a small program running in the background, which only job is to listen for an abnormal exit of the main application and then show the 'report' dialog where the user could choose to email me the output of the error.
Not really sure how to implement this, or if this is the right way to do it.
Reporting the error message would be an easy task, but I have no idea how to capture the output of an unhandled exception or grab the exit codes (I'm assuming the program would give an exit code other then 0 when it crashes).
Would be great to have a nudge in the right direction.
Start by creating a new WPF project with the name WPFExceptionHandling. Drag one textbox from the toolbox to the design window. The following XAML code creates a textbox and initializes it with some properties. Here is the file reading with exception handling in C#.
WPF only runs on windows. You can make a type of wpf application called xbap which runs in a browser. BUT. Only on windows.
WPF uses XAML as its frontend language and C# as its backend languages. WPF was introduced as a part of . NET Framework 3.0 as the Windows library to build Windows client apps and the next generation of Windows Forms. The current version of WPF is 4.5.
WPF is known as Windows Presentation Foundation. Windows Presentation Foundation is known as the development framework. WPF is also known as the sub-system of the . Net framework. Windows Presentation Foundation framework can build the Windows Client Application.
Your best chance is inside the application. There are two hooks:
AppDomain.UnhandledException
is the ultimate 'catch-all'Application.ThreadException
is the UI specific catch-all for exceptions that occurred in Forms threadsThe proper place to 'catch-all' depends on your application semantics and is difficult to say where you should put it w/o knowing your application. Application need to also set the Application.SetUnhandledExceptionMode
.
Having an external watch dog is less useful because it cannot give any meaningful information why did the application crash. By the time it detect an 'unexpected' exit (how does it knows is 'unexpected'?) is way too late to collect any useful information. With an inside handler you can collect the exception and the stack and submit them to an analysis service like bugcollect.com and then you'll have a leg ahead in understanding now only what happened, but also how often it happens and which deployment are affected (where it happens). There are other similar services like exceptioneer.com or the Windows Error Reporting (this one requires your code to be signed by a trusted authority certificate like Verisign). Relying on a service for collection of incidents is far superior to sending mail, you don't want to wake up and find 2k incident emails in your inbox and start sifting through them to understand what happened.
And a final world: don't reinvent the wheel: there are already many frameworks to collect and log exceptions, like log4net and elmah.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With