473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

top level exception handler behaves differently w/o debugger

Hi,

I've got the following code sample to reproduce my issue:

Public Class Form1
Inherits System.Windows.Forms.Form

Shared Sub main()
Try
Application.Run(New Form1)
Catch ex As Exception
Console.WriteLine("Test")
End Try

End Sub

[windows form designer generated code]

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Throw New DivideByZeroException
End Sub
End Class
I added the sub main to insert a top level exception handler in my winforms
app.

When this is run under the debugger, this works as expected. The top level
exception handler grabs the exception and it exits gracefully. Executing
without the debugger, I get the CLR unhandled exception message about an
attempt to divide by zero. Why would the behavior differ?

-Ben
Oct 3 '05 #1
5 1523
Hi Ben,

Based on my research, what you are noticing is by design. In .NET
framework, we do not bubble errors that are generated in event handlers to
the application level when there isn't a debugger attached. What we do is
propagate the error through the Application.ThreadException. This is how
1.0 and 1.1 was designed.

So you can handle the Application.ThreadException event for the application
level exception. Here is an KB article for this. HTH.

http://support.microsoft.com/default...b;en-us;836674

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Oct 4 '05 #2
Hi Kevin,

Thanks for your help. This is similar to what I found as well. When I hooked
up to that event, it was fired both when I was using the debugger and when I
was not. This seemed to require me to abandon the "bubbling" exception model.
I've never encountered a situation before where the flow of execution seems
different depending on the presence of the debugger, before. The article that
you sent is very interesting. Thanks again for your help!

-Ben

"Kevin Yu [MSFT]" wrote:
Hi Ben,

Based on my research, what you are noticing is by design. In .NET
framework, we do not bubble errors that are generated in event handlers to
the application level when there isn't a debugger attached. What we do is
propagate the error through the Application.ThreadException. This is how
1.0 and 1.1 was designed.

So you can handle the Application.ThreadException event for the application
level exception. Here is an KB article for this. HTH.

http://support.microsoft.com/default...b;en-us;836674

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Oct 5 '05 #3
Hi Kevin
Based on my research, what you are noticing is by design.
Based on the link that you posted I would say that your answer is
inconsistent with reality.

The link clearly states that this is a bug, and therefore not by design,
unless Microsoft is in the habit of designing in bugs to their products.
Perhaps you would care to comment on this? ;-)

Charles
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:Bs**************@TK2MSFTNGXA01.phx.gbl... Hi Ben,

Based on my research, what you are noticing is by design. In .NET
framework, we do not bubble errors that are generated in event handlers to
the application level when there isn't a debugger attached. What we do is
propagate the error through the Application.ThreadException. This is how
1.0 and 1.1 was designed.

So you can handle the Application.ThreadException event for the
application
level exception. Here is an KB article for this. HTH.

http://support.microsoft.com/default...b;en-us;836674

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Oct 6 '05 #4
You're welcome, Ben.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Oct 6 '05 #5
In a develpment lifecycle, when bugs are closed, some bugs are closed as by
design, because it is in the designed behavior. Not all bugs are really
bugs. I'm just providing Ben with information that you cannot see.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Oct 6 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert Rotstein | last post by:
It appears that exception handling at the top-most level of a C# program, in the static void Main() method, differs depending on whether the program is run in debug mode or not. That is, code such...
5
by: MJB | last post by:
I never get the above exception in Windows 2k. It only happens in Windows XP, which is the first oddity. My application is multi-threaded and I use the webbrowser control and media player. The...
5
by: Ben R. | last post by:
Hi, I've got the following code sample to reproduce my issue: Public Class Form1 Inherits System.Windows.Forms.Form Shared Sub main() Try Application.Run(New Form1)
15
by: Mark Lewis | last post by:
I have a weird error trapping problem. When running the IDE everything works fine but not when running in an EXE I get the Unhandled Exception Error message box intead of the one in my Try....Catch...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.