By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,508 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,508 IT Pros & Developers. It's quick & easy.

Unhandled exceptions in runtime - is it a compiler bug?

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.