C# Response.Redirect引起的错误

今天遇到一个问题,代码格式如下:

try
{
Response.Redirect("index.aspx");
}
catch(Exception ex)
{
Response.Write("错误:" + ex.ToString());
}

这里总是捕捉到错误:

System.Threading.ThreadAbortException: 正在中止线程。
   在 System.Threading.Thread.AbortInternal()
   在 System.Threading.Thread.Abort(Object stateInfo)
   在 System.Web.HttpResponse.End()
   在 System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
   在 System.Web.HttpResponse.Redirect(String url)
原来Response.Redirect会执行httpResponse.End() ,从来引起中止线程的错误,修改如下: 
catch (System.Threading.ThreadAbortException e)
{
//这个异常不需要特别处理
Debug.Write("......");
}
catch (SqlException err2)
{
。。。
}

加两上两层错误捕捉,System.Threading.ThreadAbortException e 这个不用处理,只加在其它的出错上即可。

原文地址:https://www.cnblogs.com/chendaoyin/p/3088329.html