ASP.NET Webforms 中的异常处理 [英] Exception handling in ASP.NET Webforms

查看:22
本文介绍了ASP.NET Webforms 中的异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ASP.NET Webforms 中处理异常的首选方法是什么?

What is the preferred method for handling exceptions in ASP.NET Webforms?

您有在 web.config 级别添加(我认为)的 Page_Error 方法,当发生错误时,整个站点都会被重定向到那里.

You have the Page_Error method that you add (I think) at web.config level, and the entire site gets redirected there when an error occurs.

这是否意味着您不应该在 webforms 应用程序的任何地方使用 try-catch?(假设您不想隐藏任何错误)

Does that mean you shouldn't use try-catch anywhere in a webforms application? (Assuming you don't want to hide any errors)

推荐答案

只捕获您可以处理的错误.如果您可以以允许页面继续加载的方式处理它们,那么就这样做.任何其他会破坏页面的异常都不应该在任何控件或页面中处理,因为无论如何你都无法做任何事情.让它转到 global.asax 处理程序并确保记录异常.

Only catch the errors you can handle. If you can handle them in a manner that allows the page to continue loading then do so. Any other exception that would wreck the page should not be handled in any control or page as you would not be able to do anything anyways. Let it go to the global.asax handler and make sure you log the exception.

这篇关于ASP.NET Webforms 中的异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆