问题描述
在 .NET 中不能捕获的异常列表是什么?或者在哪里可以找到这样的列表?
What is the list of exceptions that CAN'T be caught in .NET? Or where can I find such a list?
推荐答案
唯一不能直接捕获的异常是(一个框架抛出)StackOverflowException.从逻辑上讲,这是有道理的,因为此时堆栈中没有空间来处理异常.来自文档:
The only exception that cannot be caught directly is (a framework thrown) StackOverflowException. This makes sense, logically, as you don't have the space in the stack to handle the exception at that point. From the docs:
从 .NET Framework 2.0 版开始,一个 StackOverflowException 对象不能被 try-catch 块捕获,相应的进程默认终止.
ThreadAbortException 可以被捕获,但总是会被捕获被重新加注,所以有独特的行为.来自文档:
ThreadAbortException can be caught, but will always get re-raised, so has unique behavior. From the docs:
ThreadAbortException 是一种特殊的异常,可以被捕获,但会在 catch 块的末尾自动再次引发.
另请注意,某些 AccessViolationException
实例是损坏状态异常,默认情况下可能不会得到处理.这些可以处理,但需要通过属性进行额外处理.有关详细信息,请参阅处理损坏状态异常.
Also note that some AccessViolationException
instances are corrupted state exceptions, and may not get handled by default. These can be handled, but require extra handling via attributes. For details, see Handling Corrupted State Exceptions.
这篇关于无法在 .NET 中捕获的异常列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!