尝试/抓住整个C#程序可能吗? [英] Is try/catch around whole C# program possible?

查看:96
本文介绍了尝试/抓住整个C#程序可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#程序被调用:

Application.Run (new formClass ());

我想在整个事情上放一个try / catch来捕获任何未被捕获的异常。当我把它放在这个Run方法时,不会捕获异常;当程序在未捕获的异常之后终止时,控制只返回。

I'd like to put a try/catch around the whole thing to trap any uncaught exceptions. When I put it around this Run method, exceptions are not caught; control only returns here when the program terminates after an uncaught exception.

我可以在哪里可以使用try / catch来覆盖整个程序?谢谢!

Where can I put try/catch to cover the whole program? Thanks!

推荐答案

要捕获Windows窗体的未处理的异常连接
AppDomain.UnhandledException Application.ThreadException 事件。

To catch Windows Form's unhandled exceptions hook-up the AppDomain.UnhandledException and Application.ThreadException events.

感兴趣的是:管理应用程序中的意外错误

这篇关于尝试/抓住整个C#程序可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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