为什么ASP.NET抛出这么多例外? [英] Why is ASP.NET throwing so many exceptions?

查看:130
本文介绍了为什么ASP.NET抛出这么多例外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

碰巧我看过的Visual Studio调试输出了一下。我可以看到成百上千的各种异常被抛出。我查了另一种基于ASP.NET的解决方案,它是呈现相同的行为。为什么所有这些抛出的异常?我不能相信这是良好的综合性能,是吗?
看看下面的摘录。它是APPR的输出。 30秒冲浪。大多数是HttpExceptions但也有FormatExceptions和ArgumentOutOfRangeExceptions。这些都不是真正影响使用。没什么崩溃。没有任何人有一个解释,因为它似乎是正常?

 类型'System.Web.HttpException'的第一次机会异常出现在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
w3wp.exe的(托管):已加载C:\\ WINDOWS \\ Microsoft.NET \\框架\\ V2.0.50727 \\临时ASP.NET文件\\ ROOT \\ a402e511 \\ e6aaa0d​​e \\ App_Web_vdj_eurz.dll',加载的符号。
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型的第一次机会异常'System.Web.HttpException'发生在System.Web.dll中
类型则''A第一次机会异常出现在mscorlib.dll
类型则''第一个机会异常出现在mscorlib.dll
类型'System.ArgumentOutOfRangeException'第一次机会异常出现在mscorlib.dll
类型'System.ArgumentOutOfRangeException'第一次机会异常出现在mscorlib.dll
类型的System.FormatException第一个机会异常出现在mscorlib.dll
类型的System.FormatException第一个机会异常出现在mscorlib.dll


解决方案

我不知道到底是什么原因造成的,但我知道你可以找到(甚至更好,对吧?))

在Visual Studio中:


  • 单击调试菜单

  • 单击异常...

  • 检查通用语言运行时例外时抛出

这将会使Visual Studio中停止对任何异常调试器,所以你可以检查什么是真正发生的事情。 (不影响生产code,只有在VS停止)

一点题外话,你可能要实现类似<一个href=\"http://blog.tedd.no/2010/07/02/asp-net-unhandled-exception-handling-email-exception-with-minidump/\"相对=nofollow>自动异常电子邮件或类似从一个生产基地的详细信息。

请注意,你可能无法赶上在VS中所有异常的开箱(第一次例外有时可能有点难以捉摸)。如果您想更多的铁杆,你可以有Visual Studio调试器<一个href=\"http://blogs.msdn.com/b/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-$c$c.aspx\"相对=nofollow>调试.Net框架了。你的目标应该是看到完整的异常+堆栈跟踪,在大多数情况下,会告诉你所有关于什么错误。

一个好的做法是摆脱例外(找到原因并修复),不隐瞒或忽略它们。

修改

这也是一文不值的第一次机会异常都是很可能通过一个try-catch捕获异常。在.net有些内部函数将抛出当某个条件满足一个例外,这是多么的Visual Studio /调试工程的一部分,并不意味着事情已经坠毁。 Visual Studio将只是你需要他们的情况下记录这些给你,但并不意味着你必须对他们采取行动。

By coincidence I watched the debug output of Visual Studio a bit. I can see hundreds and hundreds of various exceptions being thrown. I checked another ASP.NET based solution and it is showing same behavior. Why are all those exceptions thrown? I cannot believe it is good for the overall performance, is it? Look at the excerpt below. It is the output of appr. 30 seconds surfing. Most are HttpExceptions but there are also FormatExceptions and ArgumentOutOfRangeExceptions. None of these is really affecting the usage. Nothing crashes. Does anybody have an explanation, as it seems to be "normal"?

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

解决方案

I'm not sure exactly what is causing it, but I know how you can find out (even better, right?:)).

In Visual Studio:

  • Click on "Debug" menu
  • Click on "Exceptions..."
  • Check "Thrown" on "Common Language Runtime Exceptions"

This will make Visual Studio halt the debugger on any exception so you can check what is actually happening. (does not affect production code, only halts in VS)

As a sidenote you may want to implement something like automatic exception emailing or similar to get more info from a production site.

Note that you may not be able to catch all exceptions in VS out of the box (first time exceptions may sometimes be a bit elusive). If you want to be more hardcore you can have Visual Studio debugger debug the .Net Framework too. Your goal should be to see the full exception + stack trace, that will in most cases tell you all about what is going wrong.

A good practice is to get rid of the exceptions (find cause and fix), don't hide or ignore them.

EDIT

It's also worth nothing that "first chance exceptions" are exceptions that may very well be captured by a try-catch. Some internal functions in .Net will throw an exception when a certain condition is met, this is part of how Visual Studio/debugging works and doesn't mean something has crashed. Visual Studio will log these for you just in case you need them, but it doesn't mean you have to act upon them.

这篇关于为什么ASP.NET抛出这么多例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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