Improved Unhandled Exception behavior in .net 2.0
2007-07-16 17:16
405 查看
The first thing to understand is that the UnhandledException event is not an unhandled exception "handler". Registering for the event, contrary to what the documentation says :-(, does not cause unhandled exceptions to be handled. (Since then they wouldn't be unhandled, but I'll stop with the circular reasoning already...) The UnhandledException event simply notifies you that an exception has gone unhandled, in case you want to try to save state before your thread or application dies. FWIW, I have filed a bug to get the docs fixed.
Just to complicate things, in v1.0 and 1.1, an unhandled exception did not always mean that your application would die. If the unhandled exception occurred on anything other than the main thread or a thread that began its life in unmanaged code, the CLR ate the exception and allowed your app to keep going. This was generally evil, because what would often happen was, for example, that ThreadPool threads would silently die off, one by one, until your application wasn't actually doing any work. Figuring out the cause of this kind of failure was nearly impossible. This may be why Jeff thought it worked before...he just always saw crashes on non-main threads. In v2.0, an unhandled exception on any thread will take down the application. We've found that it's tremendously easier to debug crashes than it is to debug hangs or the silent-stoppage-of-work problem described above. BTW, on my 1.1 machine the example from MSDN does have the expected output; it's just that the second line doesn't show up until after you've attached a debugger (or not). In v2 we've flipped things around so that the UnhandledException event fires before the debugger attaches, which seems to be what most people expect. Jonathan Keljo
CLR Exceptions PM http://www.codinghorror.com/blog/archives/000216.h...
Just to complicate things, in v1.0 and 1.1, an unhandled exception did not always mean that your application would die. If the unhandled exception occurred on anything other than the main thread or a thread that began its life in unmanaged code, the CLR ate the exception and allowed your app to keep going. This was generally evil, because what would often happen was, for example, that ThreadPool threads would silently die off, one by one, until your application wasn't actually doing any work. Figuring out the cause of this kind of failure was nearly impossible. This may be why Jeff thought it worked before...he just always saw crashes on non-main threads. In v2.0, an unhandled exception on any thread will take down the application. We've found that it's tremendously easier to debug crashes than it is to debug hangs or the silent-stoppage-of-work problem described above. BTW, on my 1.1 machine the example from MSDN does have the expected output; it's just that the second line doesn't show up until after you've attached a debugger (or not). In v2 we've flipped things around so that the UnhandledException event fires before the debugger attaches, which seems to be what most people expect. Jonathan Keljo
CLR Exceptions PM http://www.codinghorror.com/blog/archives/000216.h...
相关文章推荐
- Unhandled exceptions cause ASP.NET-based applications to unexpectedly quit in the .NET Framework 2.0
- Speed Up Your Site with the Improved View State in ASP.NET 2.0
- spark 2.0 遇到java.net.URISyntaxException: Relative path in absolute URI
- 就会报Unhandled exception at 0x1000a0ce (Libnet.dll) in tcp1.exe: 0xC0000005: Access violation reading location 0xfffffe64.错误。 请问为什
- Spark2.0异常:java.net.URISyntaxException: Relative path in absolute URI
- Spark2.0的Caused by: java.net.URISyntaxException: Relative path in absolute URI: file错误
- james:java.net.BindException: Address already in use
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- 安装Hive过程中,出现Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxExcepti
- Personalization in ASP.NET 1.1(Help you understand Profile in ASP.NET 2.0)
- Uploading Files in ASP.NET 2.0
- javax.net.ssl.SSLException: hostname in certificate didn't match:
- asp.net 调用 mysql 存储过程 MySql.Data.MySqlClient.MySqlException: Unhandled type encountered
- json-lib 出现net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决办法
- Exception in createBlockOutputStream java.net.SocketException: 打开的文件过多
- 解决VC 类向导添加变量后莫名其妙出现 Unhandled exception in xxx.exe:0xC0000005:Access Violation错误的问题
- net.sf.json.JSONException: There is a cycle in the
- Basic Skill in .net2.0
- Unhandled exception at 0x00000000 in CallDll.exe: 0xC0000005: Access violation reading location 0x00
- tomcat错误严重: StandardServer.await: create[8005]: java.net.BindException: Address already in use: JVM_