InnerException

在asp.net中,我在一个应用中 throw new Exception(“Text“);
然后在Global.asax中的Application_Error中捕获该异常.
  protected void Application_Error(Object sender, EventArgs e)
  {

   Exception ee = Server.GetLastError();
   if (ee != null)
   {
    Session["ErrMsg"] = ee.Message;
   }
   else
   {
    Session["ErrMsg"] = "Unknown Error";
   }

   //跳到出错页,显示Session["ErrMsg"]。

   Server.Transfer("WebForm2.aspx");
  }

结果出错页上显示的是“发生类型为 System.Web.HttpUnhandledException 的异常。

费了老多时间,作了如下修改后,显示就正确了:
 protected void Application_Error(Object sender, EventArgs e)
  {

   Exception ee = Server.GetLastError();
   if (ee != null)
   {
    Session["ErrMsg"] = ee.InnerException.Message;
   }
   else
   {
    Session["ErrMsg"] = "Unknown Error";
   }

   //跳到出错页,显示Session["ErrMsg"]。

   Server.Transfer("WebForm2.aspx");
  }
查了半天帮助,还是看的云里雾里,还请博客园的高手指点是什么原因,Microsoft设计这个InnerException到底是什么目的?

posted on 2004-04-22 20:08  一个春天  阅读(5377)  评论(5编辑  收藏  举报

导航