不是Application_Error里面可以捕获所有未处理的异常嘛,经测试的确是这样,但webmethod里面的异常却捕获不了.
1.webmethod定义:
      [WebMethod]
        public static string TestException(){throw new Exception("test exception");}
2.ajax调用:
aspx页面必须添加控件: 
   <asp:ScriptManager ID="sm1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
js调用:
PageMethods.TestException(function(){/*成功处理*/},function(){/*失败处理*/});//测试时这个方式已经执行并抛出了异常
3.异常记录(这里捕获不到异常):
    void Application_Error(object sender, EventArgs e) 
    {
        Exception objErr = Server.GetLastError().GetBaseException();
        string error =  "发生时间:" + System.DateTime.Now.ToString() + "\r\n";
        error += "发生异常页: " + Request.Url.ToString() + "\r\n";
        error += "异常信息: " + objErr.Message + "\r\n";
        error += "错误源:" + objErr.Source + "\r\n";
        error += "堆栈信息:" + objErr.StackTrace;
        SqlDataDAL.Log.Add(error);
        Server.ClearError();
    }