哪个 .config 元素会影响 UnhandledExceptionMode 设置为 UnhandledExceptionMode.Automatic 的异常处理? [英] Which .config element affects exception handling with UnhandledExceptionMode set to UnhandledExceptionMode.Automatic?

查看:36
本文介绍了哪个 .config 元素会影响 UnhandledExceptionMode 设置为 UnhandledExceptionMode.Automatic 的异常处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows 窗体应用程序,该应用程序在程序启动时包含此代码:

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);

的 MSDN 文档中UnhandledExceptionMode.Automatic 它指出:

<块引用>

自动 - 将所有异常路由到ThreadException 处理程序,除非应用程序的配置文件另有规定.

有谁确切知道配置文件中的哪个元素/属性会影响此设置?

解决方案

你可以像这样在你的配置文件中添加一个 JitDebugging 部分:

<预><代码><配置><system.windows.forms jitDebugging="true"/></配置>

这等效于将 UnhandledExceptionMode 设置为 UnhandledExceptionMode.ThrowException(顺便说一句,如果您在附加调试器的情况下运行您的应用程序,此选项将自动启用).

注意 UnhandledExceptionMode.Automatic 是 .Net 使用的默认值,除非你另外指定;据我所知,将 Unhandled Exception Mode 显式设置为 Automatic 的唯一原因是,如果您想撤消先前将其更改为其他内容的调用.请注意,如果您将其设置为自动以外的其他内容,则不会读取配置文件设置.

请注意,如果您将 ThreadException 附加到当前 AppDomain,结果将自动与您将 UnhandledExceptionMode 设置为 UnhandledExceptionMode.CatchException 一样.

I have a Windows Forms application that has this code in the program's start up:

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);

In the MSDN Documentation for UnhandledExceptionMode.Automatic it states that:

Automatic - Route all exceptions to the ThreadException handler, unless the application's configuration file specifies otherwise.

Does anyone know exactly which element/attribute in the config file it is that affects this setting?

解决方案

You can add a JitDebugging section to your config file like this:

<configuration>
  <system.windows.forms jitDebugging="true"/>
</configuration>

This is equivalent to setting the UnhandledExceptionMode to UnhandledExceptionMode.ThrowException (incidentally, if you run your application with a Debugger attached, this option is automatically enabled).

Note that UnhandledExceptionMode.Automatic is the default used by .Net unless you specify otherwise; as far as I can tell, the only reason to explicitly set the Unhandled Exception Mode to Automatic is if you want to undo a previous call that changed it to something else. Note that if you do set it to something other than Automatic, the configuration file setting will not be read.

Note that if you attach a ThreadException to the current AppDomain, the result is automatically as if you had set the UnhandledExceptionMode to UnhandledExceptionMode.CatchException.

这篇关于哪个 .config 元素会影响 UnhandledExceptionMode 设置为 UnhandledExceptionMode.Automatic 的异常处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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