加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 为什么CLR会重新抛出ThreadAbortException?

发布时间:2020-12-15 18:23:54 所属栏目:百科 来源:网络整理
导读:我从“ Windows上的并发编程”一书中获得了以下代码: void Main(){ try { try { Console.WriteLine("Inside Main Method"); Thread.CurrentThread.Abort(); } catch(ThreadAbortException) { Console.WriteLine("Inside First Catch"); // Trying to swallo
我从“ 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?

是的,有几个.例如,堆栈外和内存不足异常也有特殊行为.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读