मैंने वीएस -2008 में एक नई WPF प्रोजेक्ट शुरू की और फिर DispatcherUnhandledException
को जाल करने के लिए कुछ कोड जोड़ा। फिर मैंने Window1
पर एक फेंक अपवाद जोड़ा लेकिन त्रुटि हैडलर द्वारा फंस नहीं गई है। क्यूं कर?WPF - DispatcherUnhandledException काम नहीं कर रहा है
public App()
{
this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
}
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
System.Windows.MessageBox.Show(string.Format("An error occured: {0}", e.Exception.Message), "Error");
e.Handled = true;
}
void Window1_MouseDown(object sender, MouseButtonEventArgs e)
{
throw new NotImplementedException();
}
लिस्टिंग में कोड को छोड़कर मुख्य यूआई थ्रेड पर अपवाद फेंकता है। – svick
डाउनग्रेड ... क्योंकि उदाहरण में अपवाद मुख्य धागे पर फेंक दिया गया है –