为什么ASP.NET抛出这么多异常?

前端之家收集整理的这篇文章主要介绍了为什么ASP.NET抛出这么多异常?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
巧合我看了一下Visual Studio的调试输出。我可以看到数百和数以百计的异常被抛出。我检查了另一个基于ASP.NET的解决方案,并显示相同的行为。为什么抛出所有这些异常?我不敢相信它对整体表现有好处,是吗?
看下面的摘录。它是appr的输出。 30秒冲浪大多数是HttpExceptions,但也有FormatExceptions和ArgumentOutOfRangeExceptions。这些都没有真正影响使用。没有什么崩溃有人有解释,因为它似乎是“正常”?
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
'w3wp.exe' (Managed): Loaded 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\a402e511\e6aaa0de\App_Web_vdj_eurz.dll',Symbols loaded.
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll
A first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll
A first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll

解决方法

我不知道究竟是什么导致的,但我知道你如何找到(更好,对… :))。

在Visual Studio中:

>点击“调试”菜单
>点击“例外…”
>检查“通用语言运行时异常”中的“抛出”

这将使Visual Studio在任何异常情况下停止调试器,以便您可以检查实际发生的情况。 (不影响生产代码,只在VS中暂停)

作为旁注,您可能希望实现像automatic exception emailing或类似的东西,以从生产站点获取更多信息。

请注意,您可能无法在VS中捕获所有异常(第一次异常有时可能无法实现)。如果你想要更核心,你也可以使用Visual Studio调试器debug the .Net Framework。您的目标应该是查看完整的异常堆栈跟踪,这在大多数情况下会告诉您所有的错误

一个好的做法是摆脱异常(找到原因和修复),不要隐藏或忽略它们。

编辑

first chance exceptions”也是一个很好的例子,它可以很好地被一个try-catch捕获。当某个条件满足时,.Net中的一些内部函数将抛出异常,这是Visual Studio /调试工作的一部分,并不意味着某些事情已经崩溃。 Visual Studio会为您记录这些,以防万一你需要它们,但这并不意味着你必须对它们采取行动。

原文链接:https://www.f2er.com/aspnet/253875.html

猜你在找的asp.Net相关文章