未显示未处理的异常消息 [英] Unhandled exception message not shown

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

问题描述

我从空白项目模板创建了 Windows 窗体应用程序.似乎默认情况下未启用 .Net 未处理异常.

I created Windows Form Application from Blank Project Template. It seems like the .Net Unhandled Exception not enabled by default.

这是在应用程序几乎完成并在目标计算机上尝试时才注意到的.它在没有任何未处理的异常消息的情况下崩溃了.

It was noticed just when the application is almost done and tried on the target computer. It crashed without any Unhandled Exception message.

据了解,如果是Win Form Application Project创建的,默认开启.Net Unhandled Exception.

It is understood that, if it was created by Win Form Application Project, the .Net Unhandled Exception is enabled by default.

我们如何为现有项目启用它?

How can we enable it for the Existing project?

有没有办法,或者我们应该从模板重新创建新项目?

Is There a way, or shall we recreate New Project from the Template?

推荐答案

为了处理应用程序事件,您需要启用 VB 应用程序框架,这对于基于 Empty Project 模板的项目是无法做到的.如果您双击解决方案探索中的我的项目节点并选择应用程序页面,您将看到启用应用程序框架复选框被禁用.

In order to handle application events, you need to enable the VB Application Framework, which you cannot do for a project based on the Empty Project template. If you double-click on the My Project node in the Solution Explore and select the Application page, you'll see that the Enable application framework check box is disabled.

要启用该框,请在 VS 中关闭您的项目,然后在编辑器中从项目文件夹中打开 VBPROJ 文件.你可以使用记事本,但像 VS Code 这样的东西更好一些.在该文件中,找到第一个 PropertyGroup 元素中如下所示的行:

To enable that box, close your project in VS and then open the VBPROJ file from the project folder in an editor. You could use Notepad but something like VS Code is a bit nicer. In that file, find the line in the first PropertyGroup element that looks like this:

<MyType>Empty</MyType>

这就是指定项目模板的内容,您需要将其更改为:

That's what specifies the project template and you need to change it to this:

<MyType>WindowsForms</MyType>

保存文件并再次在 VS 中打开您的项目.如果您打开了项目属性页,那么您可能会看到一条错误消息.如果是这样,请关闭该文档窗口并重新打开它.您现在应该看到复选框已启用,因此您可以选中它,然后单击查看应用程序事件按钮并为 UnhandledException 事件创建处理程序.

Save the file and open your project in VS again. If you had the project property pages open then you may get an error message displayed. If so, close that document window and reopen it. You should now see that check box is enabled, so you can check it and then click the View Application Events button and create a handler for the UnhandledException event.

请注意,您必须选择一个表单作为项目的启动对象才能启用应用程序框架.如果您已经拥有自己的 Main 方法,那么您将无法再使用它.启用应用程序框架后,VB 会创建自己的 Main 方法,该方法对您隐藏.您需要在启动时执行的任何通常会在 Main 方法中执行的代码都应移至 Startup 事件处理程序.

Just be aware that you must have selected a form as your startup object for the project in order to enable the Application Framework. If you already have your own Main method then you will not be able to use that any more. With the Application Framework enabled, VB creates its own Main method that is hidden from you. Any code you need executed at startup that would normally go in a Main method should be moved to the Startup event handler.

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

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