我从“Windows 上的并发编程”一书中获得了以下代码:
void Main()
{
try
{
try
{
Console.WriteLine("Inside Main Method");
Thread.CurrentThread.Abort();
}
catch(ThreadAbortException)
{
Console.WriteLine("Inside First Catch");
// Trying to swallow but CLR throws it again....
}
}
catch(ThreadAbortException)
{
Console.WriteLine("Inside Second Catch");
//Thread.ResetAbort();
}
}
我想知道为什么 CLR 会重新抛出 ThreadAbortException ?它一直这样做,直到我调用“Thread.ResetAbort()”。其次,是否有任何其他系统定义的异常得到 CLR 的特殊处理?
最佳答案
I am interested in knowing as why CLR re-throws the ThreadAbortException?
因为线程正在中止。人们一直在处理所有异常,即使这样做很危险。如果一个错误记录例程让一个本应被销毁的线程永远活着,那就太奇怪了,不是吗?
is there any other system defined exception, which gets special treatment from CLR?
是的,有几个。例如,堆栈外和内存外异常也有特殊的行为。
关于c# - 为什么 CLR 会重新抛出 ThreadAbortException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8237945/