Max*_*ich 9 c# asp.net error-handling
在全局ASP.NET应用程序中捕获错误是否有任何问题(例如:Global.asax)?我已经看过一个好的错误处理实践的问题,并没有真正说太多.
我的经验是排除了一些非常具体的情况(例如事务),我们编写的大多数ASP.NET应用程序都是如此
void ButtonEventHandler(object sender, EventArgs e) {
Page.Validate();
if (Page.IsValid) {
//Do a database insert or update thru relevant datalayers.
//If its a transaction then we rollback internally and rethrow
//the exception.
}
}
Run Code Online (Sandbox Code Playgroud)
为什么不只有一个全局异常处理程序?通常(此时)我唯一能做的就是优雅地中止操作并告诉用户再试一次.