我该如何继续未处理的异常运行后? [英] How do I continue running after an unhandled exception?

查看:210
本文介绍了我该如何继续未处理的异常运行后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序下面的代码是未处理的异常运行后:

I have the following code in my application that is running after an unhandled exception:

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var exception = e.ExceptionObject as Exception;
            if (exception != null) MessageBox.Show(exception.Message + " - " + exception.StackTrace);
        }



但即使我赶上未处理的异常我的Windows Mobile应用程序关闭。如何防止关闭应用程序时,我赶上未处理的异常。我从来没有要关闭我的应用程序。我想在这种情况下还是什么都没有接近应用打开登录表单。

but even if i catch unhandled exception my windows mobile application close. How to prevent closing application when i catch unhandled exception. I never want to close my app. I want to open Login form in this scenario or anything else not close app.

所以,我想是为了防止未处理的异常关闭应用程序像网络出现故障,..

So what i want is to prevent closing application from unhandled exception like network is down,...

我不能在每个代码使用尝试捕捉....

I can not use try catch in every code ....

任何想法如何防止关闭应用程序时网络出现故障或任何其它未处理的异常?

Any idea how to prevent closing app when network is down or any other unhandled exceptions?

推荐答案

您没有。当你得到一个AppDomain未处理的异常,应用程序处于稳定状态不再。确切位置在哪里,你将恢复到?当你已经得到了这一点,你唯一的选择,有很好的理由,是退出。你可以合理安排自己再次运行,以确保应用程序回来但一个更好的想法是从源头上真正处理异常并防止它成为一个UnhandledException。

You don't. When you get an AppDomain unhandled exception, your app is no longer in a stable state. Where exactly would you resume to? When you've gotten to that point, your only option, with good reason, is to exit. You could reasonably schedule yourself to run again to make sure the app comes back, but a far better idea is to actually handle the exception at its source and prevent it from being an UnhandledException.

这篇关于我该如何继续未处理的异常运行后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆