可能重复: 异常名单,不能陷入.NET
Possible Duplicate: List of exceptions that CAN'T be caught in .NET
由于被记录,try / catch块不能处理StackOverflowException和OutOfMemoryException异常。
As is documented, try/catch blocks can't handle StackOverflowException and OutOfMemoryException.
是否还有其他的例外也从这种限制的影响?
Are there any other Exceptions that also suffer from this limitation?
杰弗里里希特在他的书CLR通过C#做出关于这一主题的几个好点,部分交易可靠度生产力。
Jeffrey Richter made several good points on this topic in his book CLR via C#, part "Trading Reliability for Productivity".
顺便说一句,您可以捕获并处理OutOfMemmory:
BTW, you can catch and handle OutOfMemmory:
出于某种原因,我不能完全解释,这种对细节的关注是不是写的时候做 code为.NET Framework。获得了内存不足的情况总是有可能 可是我几乎从来没有看到任何包含code catch块从一个恢复 OutOfMemoryException异常。事实上,我甚至有一些开发商告诉我,CLR不 让程序抓到一个OutOfMemoryException。根据记录,这是绝对不正确的; 您可以捕获该异常。事实上,有很多错误,在执行时是可能的 管理code,我几乎没有看到开发人员编写code,试图从中恢复 这些潜在的故障。
For some reason that I can’t quite explain, this attention to detail is not done when writing code for the .NET Framework. Getting an out-of-memory situation is always possible and yet I almost never see any code containing a catch block to recover from an OutOfMemoryException. In fact, I’ve even had some developers tell me that the CLR doesn’t let a program catch an OutOfMemoryException. For the record, this is absolutely not true; you can catch this exception. In fact, there are many errors that are possible when executing managed code and I hardly ever see developers write code that attempts to recover from these potential failures.