• 巧用Response.Write(message)中止异常


    public void ResponseInfo(string message)
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write(message);
                HttpContext.Current.Response.End();
            }
    

    通常网页开发中的输出信息作为一个方法 ResponseInfo() 单独调用

    但是以上方法放在 try catch中会提示 错误 System.Threading.ThreadAbortException: 正在中止线程。为什么会报这样的异常,我还没有搞明白,为了在页面上抓错我们可以换一种方式解决问题

     string error = string.Empty;   用于接收错误信息,判断是否有错误产生
     bool sucess = false;
    
    try
                {
                         . .. ..                
                   sucess = AddInfo();
                }
                catch (Exception ex)
                {
                    Eagle.Common.Utils.WriteErrorToTXT(ex.ToString());
                    error = "添加信息失败";
                }
                finally
                {
                    if (error.Length > 0)
                        ResponseInfo(error);
                }
                if (sucess)
                    ResponseInfo("sucess");
                else
                {
                    ResponseInfo("faile");
                }
    
  • 相关阅读:
    11
    TSP-test
    TSP-SA_TSP
    TSP-PathLength
    TSP-OutputPath
    TSP-NewAnswer
    TSP-
    TSp-dsxy2figxy
    TSP-DrawPath
    TSP-Distanse
  • 原文地址:https://www.cnblogs.com/needrunning/p/1886938.html
Copyright © 2020-2023  润新知