Home » Microsoft » 70-518 » What should you do?
You are designing a Windows Presentation Foundation (WPF) application by using Microsoft .NET Framework 4 and Microsoft Visual Studio 2010.The application vii use multiple worker threads and a single user interface (UI) thread.
You plan to design the exception.-handling strategy for the application.You need to ensure that all exceptions that occur can be handled.
What should you do?
A. Use a DispatcherUnhandledExceptionEvent handler on the main UI thread
B. Use a DispatcherUnhandledExceptionEvent handler on each worker thread
C. Write an AppDomain UnhandledExceptionEvent handler
D. Write a general catch block for the System Exception types after any specific catch statements on the main user interface thread
Correct Answer: C
Explanation/Reference:
There are two events you can handle to process unhandled exceptions:
¦¦ Application.DispatcherUnhandledException The right choice for catching most unhandled exceptions. You should not use DispatcherUnhandledException to dismiss events by setting DispatcherUnhandledExceptionEventArgs.Handled to True.
Instead, set DispatcherUnhandledExceptionEventArgs.Handled to False and allow the application to crash. If you dismiss an exception that your application is not unable to handle, application behavior could be unpredictable, and data might become corrupted.
¦¦ AppDomain.UnhandledException The right choice for catching unhandled exceptions in background threads . You cannot use this event to mark an exception as handled; it will continue to propagate automatically.
If you do not use background threads, you can simply handle Application.DispatcherUnhandled Exception. If you do create a background thread, handle both events with the same event handler.