473,406 Members | 2,894 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,406 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 1525
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.