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

  • 相关阅读:
    功能测试点总结
    SQL 注入
    软件特征功能测试过程分析 (引用)
    高效率测试之巧用策略模式 (引用)
    Oracle数据库安装过程中遇到的若干问题
    涉众利益分析
    问题账户需求分析
    2018春阅读计划
    《我们应当怎样做需求分析》阅读笔记
    个人总结
  • 原文地址:https://www.cnblogs.com/emanlee/p/1334463.html
Copyright © 2011-2022 走看看