WPF全局尝试捕获异常+继续运行 [英] WPF global try catch exception + continue running
本文介绍了WPF全局尝试捕获异常+继续运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好!
我想知道,是否可以将App.xaml.cs方法中的某个地方调用例如带错误的MessageBox,但继续运行?
我发现:
Hello!
I want to know, is that possible to place somewhere in App.xaml.cs method to call for example MessageBox with error, but continue running?
I found that:
Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
然后在某些窗口中引发"异常,如:
and then in some of window ''raised'' exception like :
string a = "1.5";
decimal.Parse(a);
这样不仅可以调用消息框,而且还可以关闭应用程序.
有什么帮助吗? ;)
so that calling messagebox, but also closing app.
Any help? ;)
推荐答案
您可以将
DispatcherUnhandledExceptionEventArgs
的Handled
属性设置为true
,如下所示:
You can set the
Handled
property of theDispatcherUnhandledExceptionEventArgs
totrue
, as follows:
void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// ...
e.Handled = true;
}
这篇关于WPF全局尝试捕获异常+继续运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文