UnhandledExceptionMode

UnhandledExceptionMode

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

问题描述

我有一个Windows窗体应用程序在程序启动时有这个代码:

  Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic ); 

在它说明:



>

有没有人知道配置文件中哪些元素/属性会影响这个设置?

解决方案

您可以在配置文件中添加JitDebugging部分,如下所示:

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

这相当于将UnhandledExceptionMode设置为 UnhandledExceptionMode.ThrowException

注意, UnhandledExceptionMode.Automatic

/ code>是.Net使用的默认值,除非您另行指定;根据我可以告诉,明确设置未处理异常模式为自动的唯一原因是,如果你想撤消以前的调用,将其改为其他。请注意,如果您将其设置为自动以外的设置,将不会读取配置文件设置。



请注意,如果将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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 16:32