try
{
  ..........................
  //.........................
}
catch(Exception ee)
{
   //出错的信息
   ee.Message;
}

解决方案 »

  1.   

    捕获页面错误事件:
    protected void Page_Error(object sender, System.EventArgs e)
    {
    string errMsg;
    Exception currentError = Server.GetLastError(); errMsg = "<link rel=\"stylesheet\" href=\"/ThePhile/Styles/ThePhile.CSS\">";
    errMsg += "<h1>Page Error</h1><hr/>An unexpected error has occurred on this page. The system " +
    "administrators have been notified. Please feel free to contact us with the information " +
    "surrounding this error.<br/>"+
    "The error occurred in: "+Request.Url.ToString()+"<br/>"+
    "Error Message: <font class=\"ErrorMessage\">"+ currentError.Message.ToString() + "</font><hr/>"+
    "<b>Stack Trace:</b><br/>"+
    currentError.ToString();
    //也可以把错误写进文件,或系统日志等
    Response.Write( errMsg );
    Server.ClearError();
    }
      

  2.   

    try
    {
      ..........................
    }
    catch(Exception ee)
    {
       //出错的信息
       writefile("c:\a.txt",ee.Message);//自己 写一个存文件的方法,把错误写进日志
    }