不能用try-catch块在应用code被捕获的异常 [英] Exceptions that can't be caught by try-catch block in application code

查看:173
本文介绍了不能用try-catch块在应用code被捕获的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSDN指出 StackOverflowException 可以' T为通过try-catch块,提供的.NET Framework 2

MSDN states that StackOverflowException can't be caught by try-catch block starting with .NET Framework 2.

与.NET Framework 2.0版开始,一个StackOverflowException对象不能被一个try-catch块捕获和相应的工艺,默认情况下终止。

Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default.

是否有其他异常具有相同的行为?

Are there any other exceptions with the same behavior?

推荐答案

是的,有一些人:


  • 该ThreadAbortedException是特殊的。它总是会被抓时,除非catch块调用ResetAbort重新提出()。当CLR执行线程的粗暴中止这是完全抓不到的。当在AppDomain被卸载例如,通常在程序退出完成。

  • The ThreadAbortedException is special. It will always be re-raised when caught unless the catch block calls ResetAbort(). It is entirely uncatchable when the CLR performs a rude abort of the thread. Done when the AppDomain gets unloaded for example, typically at program exit.

非托管code在一个线程中抛出的任何本地例外得到母语code开始是抓不到的。这里常见的情况是,开始自己的线程COM组件。在CLR无力陷阱这样的例外,它不知道有关线程,不能注入一个catch块。如果本地code没有捕获异常那么Windows终止进程。

Any native exceptions thrown by unmanaged code in a thread that got started by native code are uncatchable. The common scenario here is COM components that start their own threads. The CLR is powerless to trap such exceptions, it doesn't know about the thread and can't inject a catch block. If the native code doesn't catch the exception then Windows terminates the process.

这是终结抛出,除非他们是至关重要的终结任何异常。他们将中止终结器线程终止该进程。

Any exceptions thrown by finalizers, unless they are critical finalizers. They'll abort the finalizer thread which terminates the process.

在.NET 4.0开始,一个ExecutionEngineException是抓不到的。它是由CLR当它检测到它的内部数据结构被破坏抛出。最典型的是通过在垃圾收集器是太忙,就是提出了一个AccessViolationException。继续执行时,GC堆被攻破管理code是一个危险的命题,并利用,.NET 4勒令它完全。

Starting with .NET 4.0, an ExecutionEngineException is uncatchable. It is thrown by the CLR when it detects that its internal data structures are compromised. Most typically by an AccessViolationException that's raised while the garbage collector is busy. Continuing to execute managed code when the GC heap is compromised is a risky proposition, and exploitable, .NET 4 pulled the plug on it entirely.

与.NET 4.0版的CLR的开始,但也可能是美元的非托管$ C $中c p $ psent您使用早期版本的互操作,微软的安全CRT可以立即当安全问题终止程序被检测到。这不是真正的引擎盖下的异常,进程将立即终止,因为code认为这个过程妥协,不能够安全地处理异常。一种常见的情况是本地函数的栈帧被砸碎,在本土code一个普遍的问题,由病毒code用于与返回地址鼓捣运行任意code。一个攻击情形称为栈缓冲区溢出。有在CLR code一些误报,在.NET 4.0发布后早,但我没有在很长一段时间看到的。您可以触发这样一个写超出一个的 stackalloc 的界限放弃自己。

Starting with the .NET 4.0 version of the CLR, but possibly also present in unmanaged code that you interop with in earlier versions, Microsoft's secure CRT can terminate a program instantly when a security problem is detected. This is not actually an exception under the hood, the process is instantly terminated since the code considers the process compromised and not capable of safely processing exceptions. A common case is where the stack frame of native function is smashed, a common problem in native code and used by viral code to tinker with the return address to run arbitrary code. An attack scenario called "stack buffer overflow". There were a few false alarms in CLR code, early after the .NET 4.0 release but I haven't seen any in quite a while. You can trigger such an abort yourself by writing beyond the bounds of a stackalloc.

相当臭名昭著的,例外的Windows消息处理程序抛出当您运行在64位操作系统上的WOW64仿真层32位模式code和你有一个调试器附加。最有名的Winforms中的麻烦Load事件也present其他信息在其他的运行环境。丑陋的细节在<一个href=\"http://stackoverflow.com/questions/4933958/vs2010-does-not-show-unhandled-exception-message-in-a-winforms-application-on-a/4934010#4934010\">this回答。

Quite infamously, exceptions thrown by Windows message handlers when you run code in 32-bit mode in the WOW64 emulation layer on a 64-bit operating system and you have a debugger attached. Best known for the troublesome Load event in Winforms but also present for other messages and in other runtime environments. The ugly details are in this answer.

与.NET 4.5,例外,微软归类为的损坏状态异常启动的(的CSE)。他们的可以的被抓住了,但只应有史以来顶级异常处理程序不为用户的利益做任何事情,但产生的诊断和无条件终止应用程序来完成。新闻背景是这本杂志的文章使用

Starting with .NET 4.5, exceptions that Microsoft classifies as Corrupted State Exceptions (CSEs). They can be caught, but that should only ever be done by a top-level exception handler that doesn't do anything but generate a diagnostic for the user's benefit and terminates the app unconditionally. Backgrounder is available in this magazine article.

这是由抖动的的您code就可以开始运行不能被捕获或报告抛出的任何异常。否则编译Main()方法是常见的情况,通常出现FileNotFoundException。

Any exception that is thrown by the jitter before your code can start running cannot be caught or reported. Failure to compile your Main() method is the common case, typically a FileNotFoundException.

这篇关于不能用try-catch块在应用code被捕获的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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