我从“
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?
是的,有几个.例如,堆栈外和内存不足异常也有特殊行为.