zoukankan      html  css  js  c++  java
  • 由Response.Redirect引发的"Thread was being aborted. "异常的处理方法

    将Response.Redirect写入try...catch会出现异常
    try 

        Response.Redirect(
    "Index.aspx"); 

    catch(Exception e) 

        Response.Redirect(
    "Error.aspx?message=" + e.Message); 

    如上,则会显示"Thread was being aborted. "异常

    同样的还有Response.End()等提前结束当前Theard的方法

    解决方案一:

    如果 Response.Redirect("Index.aspx"); 必须写到Try{}里,则可以在Catch语句写入:

    catch(Exception e) 

        
    if (!(e is ThreadAbortException)) 
        { 
            Response.Redirect(
    "Error.aspx?message=" + e.Message); 
        } 
    }
      略过系统对这个特殊异常的处理。

     解决方案二:

    MSDN已经解析清楚了
    “调用 Redirect 等效于在将第二个参数设置为 true 的情况下调用 Redirect。 Redirect 调用 End,它在完成时引发 ThreadAbortException 异常。” 可见Redirect方法在内部是调用 Thread.Abort()来中止线程的从而引发ThreadAbortException 异常。如果不想立刻中止则,第二个参数设置为false

    C# code

    protected void Button1_Click(object sender, EventArgs e)
    {
    try
    {
    Response.Redirect(
    "A.aspx",false);
    }
    catch( Exception e1)
    {
    Response.Redirect(
    "B.aspx");
    }
    }

     From:

    http://topic.csdn.net/u/20080909/10/fa572c74-5f5b-4996-a649-36691fcfadcb.html

    http://www.zxbc.cn/html/20071128/29848.html

  • 相关阅读:
    欧拉路问题
    树上依赖背包总结
    树状数组的应用
    KMP
    深探树形dp
    再探树形dp
    日常水题
    深入hash
    同一控制下的企业合并,长期股权投资成本与支付账面之间的差额计入资本公积
    资本公积冲减留存收益
  • 原文地址:https://www.cnblogs.com/emanlee/p/1334463.html
Copyright © 2011-2022 走看看