62,253
社区成员
发帖
与我相关
我的任务
分享void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
Result result = new Result();
result.code = "-1";
result.msg = Server.GetLastError().ToString();
if (Context != null)
Context.ClearError();
Response.ContentType = "text/plain";
Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(result));
}
我现在的解决办法是在每个被ajax的页面都try了,catch部分都是相同代码,本来想是操作数据库的时候再try,但是页面首先就判断参数分支了,必须得分支前就try,差不多就是整个页面都在try内了。问题是解决了,但重复代码太多了,看着不太舒服,今天重温书籍,看到Appliction对象,才想着能不能去掉这些重复代码
请教,达到我想要的目的的方法,实际我不是想自定义错误,我是想把错误信息原封不动地返回给客户端的,这样容易判断错误出现的位置