zoukankan      html  css  js  c++  java
  • 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 这个不用处理,只加在其它的出错上即可。

  • 相关阅读:
    hdu 2680(最短路)
    hdu 1548(最短路)
    hdu 1596(最短路变形)
    hdu 1546(dijkstra)
    hdu 3790(SPFA)
    hdu 2544(SPFA)
    CodeForces 597B Restaurant
    CodeForces 597A Divisibility
    CodeForces 598E Chocolate Bar
    CodeForces 598D Igor In the Museum
  • 原文地址:https://www.cnblogs.com/chendaoyin/p/3088329.html
Copyright © 2011-2022 走看看