473,414 Members | 1,720 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,414 software developers and data experts.

Unhandled exceptions in runtime - is it a compiler bug?

Hi everybody,

let me start with a simple sample to replicate the problem:

1. Create a new Windows Application C# project with 2 forms - MainForm and
FaultyForm;

2. In the faulty form override the OnLoad method to throw an exception:
public partial class FaultyForm : Form
...
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
throw new ApplicationException("Oops......");
}

3. Add a button to the MainForm and on button click event try to ShowDialog
of a FaultyForm, of course in a try...catch block:
public partial class MainForm : Form
...
private void clickMeButton_Click(object sender, EventArgs e)
{
try
{
FaultyForm f = new FaultyForm();
f.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Handled Exception",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
==============================================

Now, if you will run this sample inside your VS in debug mode, everything is
fine. The exception will be handled and you will get a nice error message.
The interesting part is that if you will do "Start without debugging" or just
try to execute an .exe file, the exception will not be handled and
applications will crash !!!

Now imagine my frustration when I was getting complains that my applications
do crash in production while I was very carefully debugging them and could
not replicate the problem :(

While I understand that I can and probably should handle exception inside
every method of every form, I do believe that this is a bug in VS.

If anybody can suggest how I can ensure that my application that is
currently in production (a pretty big project) will not carsh without
revisiting every method in the child forms and wiring events to propogate
child form exceptions to the main form without crashing an application, I
would highly appretiate !

Also, would be nice to know if Microsoft is aware of this problem and what
do they say, as I didn't find out any information about that.
--
Thanks,
Viktar Z.
Sep 13 '06 #1
6 1652
Viktar,
I think the main issue here is one of understanding the execution environment.

When code is executed in Visual Studio, this is a much different execution
environment than when code is deployed as a release build. As a release,
there is no IDE and no IDE debugger to attach and break into the editor.

There are some events you can catch and ways to wrap your code in unhandled
exception blocks that will aid in making sure you can "clean up" your
application. But the bottom line is that if your app throws an unhandled
exception in .NET 2.0, the appdomain unwinds and that's the end of it.
Peter

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Viktar Zhardzetski" wrote:
Hi everybody,

let me start with a simple sample to replicate the problem:

1. Create a new Windows Application C# project with 2 forms - MainForm and
FaultyForm;

2. In the faulty form override the OnLoad method to throw an exception:
public partial class FaultyForm : Form
...
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
throw new ApplicationException("Oops......");
}

3. Add a button to the MainForm and on button click event try to ShowDialog
of a FaultyForm, of course in a try...catch block:
public partial class MainForm : Form
...
private void clickMeButton_Click(object sender, EventArgs e)
{
try
{
FaultyForm f = new FaultyForm();
f.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Handled Exception",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
==============================================

Now, if you will run this sample inside your VS in debug mode, everything is
fine. The exception will be handled and you will get a nice error message.
The interesting part is that if you will do "Start without debugging" or just
try to execute an .exe file, the exception will not be handled and
applications will crash !!!

Now imagine my frustration when I was getting complains that my applications
do crash in production while I was very carefully debugging them and could
not replicate the problem :(

While I understand that I can and probably should handle exception inside
every method of every form, I do believe that this is a bug in VS.

If anybody can suggest how I can ensure that my application that is
currently in production (a pretty big project) will not carsh without
revisiting every method in the child forms and wiring events to propogate
child form exceptions to the main form without crashing an application, I
would highly appretiate !

Also, would be nice to know if Microsoft is aware of this problem and what
do they say, as I didn't find out any information about that.
--
Thanks,
Viktar Z.
Sep 13 '06 #2
I found a KB article, if enybody else is interested:

http://support.microsoft.com/kb/324653/en-us

--
Thanks,
Viktar Z.
"Viktar Zhardzetski" wrote:
Hi everybody,

let me start with a simple sample to replicate the problem:

1. Create a new Windows Application C# project with 2 forms - MainForm and
FaultyForm;

2. In the faulty form override the OnLoad method to throw an exception:
public partial class FaultyForm : Form
...
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
throw new ApplicationException("Oops......");
}

3. Add a button to the MainForm and on button click event try to ShowDialog
of a FaultyForm, of course in a try...catch block:
public partial class MainForm : Form
...
private void clickMeButton_Click(object sender, EventArgs e)
{
try
{
FaultyForm f = new FaultyForm();
f.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Handled Exception",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
==============================================

Now, if you will run this sample inside your VS in debug mode, everything is
fine. The exception will be handled and you will get a nice error message.
The interesting part is that if you will do "Start without debugging" or just
try to execute an .exe file, the exception will not be handled and
applications will crash !!!

Now imagine my frustration when I was getting complains that my applications
do crash in production while I was very carefully debugging them and could
not replicate the problem :(

While I understand that I can and probably should handle exception inside
every method of every form, I do believe that this is a bug in VS.

If anybody can suggest how I can ensure that my application that is
currently in production (a pretty big project) will not carsh without
revisiting every method in the child forms and wiring events to propogate
child form exceptions to the main form without crashing an application, I
would highly appretiate !

Also, would be nice to know if Microsoft is aware of this problem and what
do they say, as I didn't find out any information about that.
--
Thanks,
Viktar Z.
Sep 18 '06 #3

"Viktar Zhardzetski" <Vi***************@discussions.microsoft.comwrot e in
message news:D5**********************************@microsof t.com...
|I found a KB article, if enybody else is interested:
|
| http://support.microsoft.com/kb/324653/en-us
|
| --

Did you notice that this is only valid for the Framework versions 1.0 and
1.1? Are you still running these?

Willy.
Sep 19 '06 #4
I am having this problem in both 1.1 and 2.0. But since they are saying this
is behavior by design, I doubt they going to change anything.

Actually, Microsoft support pointed me to that article.

--
Thanks,
Viktar Z.
"Willy Denoyette [MVP]" wrote:
>
"Viktar Zhardzetski" <Vi***************@discussions.microsoft.comwrot e in
message news:D5**********************************@microsof t.com...
|I found a KB article, if enybody else is interested:
|
| http://support.microsoft.com/kb/324653/en-us
|
| --

Did you notice that this is only valid for the Framework versions 1.0 and
1.1? Are you still running these?

Willy.
Sep 19 '06 #5

"Viktar Zhardzetski" <Vi***************@discussions.microsoft.comwrot e in
message news:FE**********************************@microsof t.com...
|I am having this problem in both 1.1 and 2.0. But since they are saying
this
| is behavior by design, I doubt they going to change anything.
|
| Actually, Microsoft support pointed me to that article.
|

Yep, I see what this is all about, and yes it's by design, I would love to
see an update of the article, so I posted a update request.

Willy.

Sep 19 '06 #6
If it is by design then IMO the design needs to be changed. I never did like
the way exceptions in forms were handled.

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>
"Viktar Zhardzetski" <Vi***************@discussions.microsoft.comwrot e
in
message news:FE**********************************@microsof t.com...
|I am having this problem in both 1.1 and 2.0. But since they are saying
this
| is behavior by design, I doubt they going to change anything.
|
| Actually, Microsoft support pointed me to that article.
|

Yep, I see what this is all about, and yes it's by design, I would love to
see an update of the article, so I posted a update request.

Willy.

Sep 19 '06 #7

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

Similar topics

24
by: mag31 | last post by:
Is there any way to find out if a particular .net function will throw an exception without first generating the exception? I am using structured exception handling i.e. try catch finally blocks...
2
by: Colin Thomsen | last post by:
I have a native VC++ application which runs differently (incorrectly) if the .NET framework is installed. A trimmed version of the app is shown below. The intention is for the SEHHandler to...
5
by: terry | last post by:
Hi, Question: When using Framesets and Server.Transfer in the Application_Error event handler is there a mechanism to get the error page to display in the total view of the browser not just in...
4
by: Frank | last post by:
Hi, I made a handler for unhandled errors. But before that is executed, VB.NET gives me the standard error window. In VB6 there was a setting (errortrapping) about handling errors in the design...
5
by: Samuel R. Neff | last post by:
When you have an unhandled exception in vb.net how do you view the exception information in the debugger? In C# the debugger creates a local variable that points to the exception and you can...
2
by: Bob | last post by:
I MUST be able to trap unhandled exceptions, bring the thread to a routine that then closes the thread on which the execption occurred without closing or affecting the other threads. Think of an...
3
by: Larry Herbinaux | last post by:
I have built an asychronous TCP Server that uses the thread pool. I have two levels of exception handling in case the handling of the inner catch block throws an exception. The outer catch block...
1
by: bg_ie | last post by:
Hi, I have the following Program.cs - namespace TestFrameworkApplication { static class Program { /// <summary> /// The main entry point for the application.
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.