Is there any way to handle all Errors Exceptions and crashes in WPF application?
I know about DispatcherUnhandledException
, but it handles only exceptions in UI thread, doesn't it?
Is there a way to catch and log all exceptions in other threads and binding errors too?
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#.
try catch finally 2. Use error events to deal with exceptions within the scope of an object. Page_Error Global_Error Application_Error 3. Use custom error pages to display informational messages for unhandled exceptions within the scope of a Web application.
AppDomain.CurrentDomain.UnhandledException
Will catch any unhandled exceptions for the current thread. This is how we handle it in our application.
BindingErrors are always handled and logged to the output window. Before a release we check the output window for binding errors and fix as many as we can.
However it is my opinion that you would not want to treat binding errors as unhandled as they mostly recoverable and should be fixed as best you can before each release. You can change Debug > Exeptions in Visual Studio to make it throw BindingFailure to get more specific information.
Yes, there are 3 places:
Application.Run()
into try
... catch
DispatcherUnhandledException
AppDomain.CurrentDomain.UnhandledException
In either case you should display a please-forgive-me message and suggest to send an error report.
The service on your server should answer either 'thank you for submitting error report' or 'the problem is already fixed in the next version. please update'
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