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

c# – 如何自动重新引发异常

发布时间:2020-12-15 23:55:08 所属栏目:百科 来源:网络整理
导读:如果在try catch块中包装对HttpResponse.End的调用,则会自动重新引发ThreadAbortException.我假设即使你在try catch块中包装try catch块也是如此. 我怎样才能完成同样的事情?我没有这方面的实际应用程序. namespace Program{ class ReJoice { public void E
如果在try catch块中包装对HttpResponse.End的调用,则会自动重新引发ThreadAbortException.我假设即使你在try catch块中包装try catch块也是如此.

我怎样才能完成同样的事情?我没有这方面的实际应用程序.

namespace Program
{
    class ReJoice
    {
        public void End() //This does not automatically re-raise the exception if caught.  
        {
            throw new Exception();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ReJoice x = new ReJoice();
                x.End();
            }
            catch (Exception e) {}
        }
    }
}

解决方法

您无法更改普通例外以获得此行为. ThreadAbortException对此有特殊支持,您无法在C#中实现自己.

ThreadAbortException is a special exception that can be caught,but it will automatically be raised again at the end of the catch block.

(编辑:李大同)

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

    推荐文章
      热点阅读