如何自动重新引发异常

Bri*_*ian 3 c# asp.net exception

如果将调用包装HttpResponse.End在try catch块中,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) {}
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ers 7

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

ThreadAbortException是一个可以捕获的特殊异常,但它会在catch块的末尾自动再次引发.