473,397 Members | 2,099 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,397 software developers and data experts.

Stopping application crashing when there is an unhandled exception

Hi,

I've recently ported a .Net 1.1 application to .Net 2.0 and the one new
feature that is getting on my nerves is that when there is an unhandled
exception the application completely crashes, causing user to loose all
the work they have done where they could previously just click continue
and in 99% of cases be fine. Is there an option to turn this annoying
crash and loose everything option off, I can see it has its merits but
in my case its just annoying.

Joe.

Jan 4 '07 #1
20 11414
<jo**************@hotmail.comwrote in message
news:11*********************@s34g2000cwa.googlegro ups.com...
I've recently ported a .Net 1.1 application to .Net 2.0 and the one new
feature that is getting on my nerves is that when there is an unhandled
exception the application completely crashes, causing user to loose all
the work they have done where they could previously just click continue
and in 99% of cases be fine. Is there an option to turn this annoying
crash and loose everything option off, I can see it has its merits but
in my case its just annoying.
Well, the first question I guess is why might there be an unhandled
exception...? Are you not using exception handling i.e.
Try...Catch[...Finally]?

Secondly, why does your Global.asax not have an Application_Error
routine...?
Jan 4 '07 #2

Mark Rae wrote:
<jo**************@hotmail.comwrote in message
news:11*********************@s34g2000cwa.googlegro ups.com...
I've recently ported a .Net 1.1 application to .Net 2.0 and the one new
feature that is getting on my nerves is that when there is an unhandled
exception the application completely crashes, causing user to loose all
the work they have done where they could previously just click continue
and in 99% of cases be fine. Is there an option to turn this annoying
crash and loose everything option off, I can see it has its merits but
in my case its just annoying.

Well, the first question I guess is why might there be an unhandled
exception...? Are you not using exception handling i.e.
Try...Catch[...Finally]?

Secondly, why does your Global.asax not have an Application_Error
routine...?
The main cause of exceptions has been cross thread exceptions on
controls, which I know can be set to be allowed but I do want to root
them all out. Also as a general preference if a new bug finds its way
in I'd prefer the user to at least have the option to try to continue.

It handles the "AppDomain.CurrentDomain.UnhandledException" to log the
problem if thats what you mean, but after this the application still
exits.

All I'm really asking is there a way to avoid the application closing
on an unhandled exception, not how to avoid unhandled exceptions.

Jan 4 '07 #3
<jo**************@hotmail.comwrote in message
news:11*********************@11g2000cwr.googlegrou ps.com...
It handles the "AppDomain.CurrentDomain.UnhandledException" to log the
problem if thats what you mean, but after this the application still
exits.

All I'm really asking is there a way to avoid the application closing
on an unhandled exception, not how to avoid unhandled exceptions.
http://www.developer.com/net/asp/article.php/961301
Jan 4 '07 #4
<jo**************@hotmail.comwrote in message
news:11*********************@11g2000cwr.googlegrou ps.com...
>
Mark Rae wrote:
><jo**************@hotmail.comwrote in message
news:11*********************@s34g2000cwa.googlegr oups.com...
I've recently ported a .Net 1.1 application to .Net 2.0 and the one new
feature that is getting on my nerves is that when there is an unhandled
exception the application completely crashes, causing user to loose all
the work they have done where they could previously just click continue
and in 99% of cases be fine. Is there an option to turn this annoying
crash and loose everything option off, I can see it has its merits but
in my case its just annoying.

Well, the first question I guess is why might there be an unhandled
exception...? Are you not using exception handling i.e.
Try...Catch[...Finally]?

Secondly, why does your Global.asax not have an Application_Error
routine...?

The main cause of exceptions has been cross thread exceptions on
controls, which I know can be set to be allowed but I do want to root
them all out. Also as a general preference if a new bug finds its way
in I'd prefer the user to at least have the option to try to continue.

It handles the "AppDomain.CurrentDomain.UnhandledException" to log the
problem if thats what you mean, but after this the application still
exits.

All I'm really asking is there a way to avoid the application closing
on an unhandled exception, not how to avoid unhandled exceptions.

What do you mean with " cross thread exceptions on controls"? Web controls don't have thread
affinity, why should you ever get this kind of exceptions? Am I missing something?

Willy.

Jan 4 '07 #5
What do you mean with " cross thread exceptions on controls"? Web
controls don't have thread affinity, why should you ever get this
kind of exceptions? Am I missing something?
Unless I blinked, the OP never mentioned web; Mark did (via
Global.asax)

Marc
Jan 4 '07 #6

Mark Rae wrote:
<jo**************@hotmail.comwrote in message
news:11*********************@11g2000cwr.googlegrou ps.com...
It handles the "AppDomain.CurrentDomain.UnhandledException" to log the
problem if thats what you mean, but after this the application still
exits.

All I'm really asking is there a way to avoid the application closing
on an unhandled exception, not how to avoid unhandled exceptions.

http://www.developer.com/net/asp/article.php/961301
Its a application, not web application

Jan 4 '07 #7
"Marc Gravell" <ma**********@gmail.comwrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
>What do you mean with " cross thread exceptions on controls"? Web
controls don't have thread affinity, why should you ever get this kind of
exceptions? Am I missing something?

Unless I blinked, the OP never mentioned web; Mark did (via Global.asax)
Apologies for causing any confusion - I quoted the link as an example of
global exception handing - probably should have looked for a WinForms one,
really...
Jan 4 '07 #8
You should handle unhandled exceptions :).

Code in your Program class will be like this:
//Main method:

Application.ThreadException += new
ThreadExceptionEventHandler(OnThreadException);
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new formMDI());

//event handlers
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
MessageBox.Show("CurrentDomain_UnhandledException: " +
e.ExceptionObject);
}

private static void OnThreadException(object sender,
ThreadExceptionEventArgs t)
{
MessageBox.Show("OnThreadException: " + t.Exception);
}

Best Regards,
Boban

*** Sent via Developersdex http://www.developersdex.com ***
Jan 4 '07 #9

Boban Stojanovski wrote:
You should handle unhandled exceptions :).

Code in your Program class will be like this:
//Main method:

Application.ThreadException += new
ThreadExceptionEventHandler(OnThreadException);
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new formMDI());

//event handlers
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
MessageBox.Show("CurrentDomain_UnhandledException: " +
e.ExceptionObject);
}

private static void OnThreadException(object sender,
ThreadExceptionEventArgs t)
{
MessageBox.Show("OnThreadException: " + t.Exception);
}

Best Regards,
Boban

*** Sent via Developersdex http://www.developersdex.com ***
I have similar code in my app, but after the UnhandledException is
handled, the application still exits, what I need is to be able to
continue running the program like you can in .Net 1.1

Jan 4 '07 #10
Hi,

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
<jo**************@hotmail.comwrote in message
news:11*********************@s34g2000cwa.googlegro ups.com...
>I've recently ported a .Net 1.1 application to .Net 2.0 and the one new
feature that is getting on my nerves is that when there is an unhandled
exception the application completely crashes, causing user to loose all
the work they have done where they could previously just click continue
and in 99% of cases be fine.
Well, you have to start handling your errors :) , if you know an operation
may fail wrap it in try/catch

The application will ends when it find an error that was not handled. I
don't see nothing wrong with that.

It's your responsability to either save the work and/or correctly handle the
errors.

--
Ignacio Machin
machin AT laceupsolutions com
Jan 4 '07 #11
Hi,

<jo**************@hotmail.comwrote in message
news:11*********************@11g2000cwr.googlegrou ps.com...
>
The main cause of exceptions has been cross thread exceptions on
controls, which I know can be set to be allowed but I do want to root
them all out.
You should then correctly handle that case, you should not try to update the
UI from a worker thread, if you do you may get problems (even if not an
exception) these are the kind of problems that are hard to find/correct.

Jan 4 '07 #12
I'm not asking for advice on how to handle errors, I'm asking if it is
possible to stop .Net 2.0 from exiting the application in exactly the
same way .Net 1.1 does when there is an unhandled exception..

Please dont answer with code suggestions to prevent unhandled
exceptions occuring, its a simple question.

Jan 4 '07 #13
The application will ends when it find an error that was not handled. I
don't see nothing wrong with that.
I see no problem with this been the default, but to make it the only
possible option, especially when it was not the case in previous
versions is annoying and not very backward compatible. I was kinda
hoping there would be a flag like the one for CrossThreadOperations on
controls or a way to stop the application closing in the
OnUnhandledException event.

Jan 4 '07 #14
"Marc Gravell" <ma**********@gmail.comwrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
>What do you mean with " cross thread exceptions on controls"? Web controls don't have
thread affinity, why should you ever get this kind of exceptions? Am I missing something?

Unless I blinked, the OP never mentioned web; Mark did (via Global.asax)

Marc
Right I see :-(

Willy.

Jan 4 '07 #15
Well, my exception handler doesn't close the application, so you must
be doing something wrong. Are you sure you're attaching a listener to
the System.Windows.Forms.Application.ThreadException event?

A better way to handle this though would be to fix the cause of the
exceptions.

jo**************@hotmail.com wrote:
The application will ends when it find an error that was not handled. I
don't see nothing wrong with that.

I see no problem with this been the default, but to make it the only
possible option, especially when it was not the case in previous
versions is annoying and not very backward compatible. I was kinda
hoping there would be a flag like the one for CrossThreadOperations on
controls or a way to stop the application closing in the
OnUnhandledException event.
Jan 4 '07 #16
Well, my exception handler doesn't close the application, so you must
be doing something wrong. Are you sure you're attaching a listener to
the System.Windows.Forms.Application.ThreadException event?

A better way to handle this though would be to fix the cause of the
exceptions.

One final note, there are some exceptions like OutOfMemoryException
that cannot be caught.

jo**************@hotmail.com wrote:
The application will ends when it find an error that was not handled. I
don't see nothing wrong with that.

I see no problem with this been the default, but to make it the only
possible option, especially when it was not the case in previous
versions is annoying and not very backward compatible. I was kinda
hoping there would be a flag like the one for CrossThreadOperations on
controls or a way to stop the application closing in the
OnUnhandledException event.
Jan 4 '07 #17
I see no problem with this been the default, but to make it the only
possible option, especially when it was not the case in previous
versions is annoying and not very backward compatible.
The only difference now is that before your apps were working incorrectly
and you didn't realize it, now your app works incorrectly and you do realize.
I would say that trying to be backwards compatible would be the wrong thing
to do, better to let the user know something has gone wrong and lose data
upto a certain point rather than let them continue and possibly lose even
more work.

Mark.
--
http://www.markdawson.org
http://themightycoder.spaces.live.com
"jo**************@hotmail.com" wrote:
The application will ends when it find an error that was not handled. I
don't see nothing wrong with that.

I see no problem with this been the default, but to make it the only
possible option, especially when it was not the case in previous
versions is annoying and not very backward compatible. I was kinda
hoping there would be a flag like the one for CrossThreadOperations on
controls or a way to stop the application closing in the
OnUnhandledException event.

Jan 5 '07 #18
You can force the 2.0 runtime to use the same default behavior for unhandled
exceptions as the 1.1 runtime. There's a compatibility flag called
legacyUnhandledExceptionPolicy that you can add to the app.config file,
as...
<legacyUnhandledExceptionPolicy enabled="1"/>This link explains it:
http://msdn2.microsoft.com/en-us/lib...65(VS.80).aspx

I suggest only using this flag when using 3rd party libraries that you
cannot get fixed: there's never a good reason to use it for your own code.

<jo**************@hotmail.comwrote in message
news:11*********************@s34g2000cwa.googlegro ups.com...
Hi,

I've recently ported a .Net 1.1 application to .Net 2.0 and the one new
feature that is getting on my nerves is that when there is an unhandled
exception the application completely crashes, causing user to loose all
the work they have done where they could previously just click continue
and in 99% of cases be fine. Is there an option to turn this annoying
crash and loose everything option off, I can see it has its merits but
in my case its just annoying.

Joe.

Jan 5 '07 #19
You can force the 2.0 runtime to use the same default behavior for unhandled
exceptions as the 1.1 runtime. There's a compatibility flag called
legacyUnhandledExceptionPolicy that you can add to the app.config file,
as...
<legacyUnhandledExceptionPolicy enabled="1"/>This link explains it:
http://msdn2.microsoft.com/en-us/lib...65(VS.80).aspx

I suggest only using this flag when using 3rd party libraries that you
cannot get fixed: there's never a good reason to use it for your own code.
Thanks, thats exactly what I'm after.

I can see the point about not using this flag out of principle, but at
present I have an app that has a couple of months of new development in
2.0 and will take another couple of months of make bug free in 2.0,
faced with a choice between rolling back 2 months work, repeating and
spending 2 months fixing bugs before getting onto 2.0 and using a flag
to allow me to continue using the newer version while fixing the bugs,
I'm happy using the flag.

Jan 5 '07 #20
Glad it helped, but there's nothing more permanent then a temporary fix. I
personally believe that threading and error handling is so important that I
would stop all other work until those problems were resolved. The more code
that gets piled on top of buggy code the harder it is to fix.
<jo**************@hotmail.comwrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
>You can force the 2.0 runtime to use the same default behavior for
unhandled
exceptions as the 1.1 runtime. There's a compatibility flag called
legacyUnhandledExceptionPolicy that you can add to the app.config file,
as...
<legacyUnhandledExceptionPolicy enabled="1"/>This link explains it:
http://msdn2.microsoft.com/en-us/lib...65(VS.80).aspx

I suggest only using this flag when using 3rd party libraries that you
cannot get fixed: there's never a good reason to use it for your own
code.

Thanks, thats exactly what I'm after.

I can see the point about not using this flag out of principle, but at
present I have an app that has a couple of months of new development in
2.0 and will take another couple of months of make bug free in 2.0,
faced with a choice between rolling back 2 months work, repeating and
spending 2 months fixing bugs before getting onto 2.0 and using a flag
to allow me to continue using the newer version while fixing the bugs,
I'm happy using the flag.

Jan 5 '07 #21

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

Similar topics

3
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
1
by: mike | last post by:
My program is crashing, but it doesn't crash on a single line of code. Below is what the output tab displays. I have no idea where to start inorder to debug this problem. Is there any suggesstions...
5
by: Dave Stewart | last post by:
I recently wrote my first Vb.net application, or at least my first complex app since moving up from vb6. When run from the VS.NET IDE, the program shows no errors and runs fine. When the output exe...
5
by: Lucvdv | last post by:
Can someone explain why this code pops up a messagebox saying the ThreadAbortException wasn't handled? The first exception is reported only in the debug pane, as expected. The second (caused by...
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...
5
by: Simon Tamman {Uchiha Jax} | last post by:
Now this is bugging me. I just released software for a client and they have reported an unhandled stack overflow exception. My first concern is that the entirity of the UI and any threaded...
1
by: Bob | last post by:
In Vs 2005 you have new applicationsEvents.vb I was testing it in a simple app and found that it was easier to implement unhandled exception management tah it was in Vs2003 (vb.net) You can, if you...
5
by: =?Utf-8?B?c3VydHVyeg==?= | last post by:
Hi, I feel like a noob for asking this. When I publish a VB windows application, I want to disable the ability of the the user to continue when there is an unhandled exception. For example,...
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
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
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...
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,...
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...

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.