Home » Microsoft » 70-518 » What should you do?
You are designing a complex and critical Windows desktop application by using Microsoft .NET Framework 4 and Microsoft Visual Studio 2010.
You plan to implement a logging strategy for the application.
You need to record all unexpected errors that occur in the application.
What should you do?
A. . Subscribe to the unhandled exception event handler for the AppDomain object.
. Record relevant application-specific information to an external log.
B. . Subscribe to the unhandled exception event handler for the application’s dispatcher on the main application thread.
. Record relevant application-specific information to an external log.
C. . Create a generic catch (Exception e) block in the Main method of the application.
. Record relevant application-specific information to a log in the Main method.
D. . Create a global WIN 32 unhandled exception filter.
. Record relevant application-specific information to an external log from within the filter.
Correct Answer: A
Explanation/Reference:
*A* (If you believe that since the app is described a critical and complex and we can assume that the application has background threads).
References:
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.