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

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 这个不用处理,只加在其它的出错上即可。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
猜你喜欢
  • 2021-06-22
  • 2021-08-04
  • 2022-12-23
  • 2021-08-02
  • 2021-11-04
  • 2022-01-27
  • 2022-12-23
相关资源
相似解决方案