处理未处理的异常问题 [英] Handling unhandled exceptions problem

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

问题描述

我想设置一些处理程序的一切,我可能没有我的code内引起了意外的异常。在 Program.Main()我用下面的code:

I wanted to set some handler for all the unexpected exceptions that I might not have caught inside my code. In Program.Main() I used the following code:

AppDomain.CurrentDomain.UnhandledException
    += new UnhandledExceptionEventHandler(ErrorHandler.HandleException);

但它没有工作,我的预期。当我开始在调试模式下的应用程序,并抛出一个异常它没有调用处理程序,但事后在Visual Studio中的异常助手弹出,如果发生异常,没有任何处理。我试过Application.Exit()处理程序内,但它并没有正常工作。

But it didn't work as I expected. When I started the application in debugging mode and threw an exception it did call the handler, but afterwards the exception helper in Visual Studio popped up as if the exception occurred without any handling. I tried Application.Exit() inside the handler but it didn't work as well.

我想实现的是,除了与我的处理程序处理,然后该应用程序很好地关闭。是否有任何其他的方式来做到这一点,或正在使用上述错误的方式code我?

What I would like to achieve is that the exception is handled with my handler and then the application closes nicely. Is there any other way to do it or am I using the code above in the wrong way?

推荐答案

这是因为你通过Visual Studio在调试模式下运行它。如果释放并安装你的应用程序在其他地方,无非是全局异常处理程序将被处理。

It's because you're running it through Visual Studio in Debug mode. If you release and install your app somewhere else, nothing but your global exception handler will be processed.

这篇关于处理未处理的异常问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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