473,503 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nice exceptions.

I'm new to VS2005, I used VS2003 a bit, and I remember it didn't act
like this.

My code looks like :

try
{
blah
blah
blah
}
catch (Exception)
{
MyOwnException myoe = new MyOwnException ("Error on receiving data");
throw myoe;
}

And what I get when an error happens is a window telling me :
"Application1 has encountered a problem and needs to close.
Send Error Report Don't Send"

Then after clicking either "Send" or "Not Send", the windows closes and
the program vanishes.

As far as I remember I'm catching the exception and the program should
be keep working after that.

Where's my fault ?

Sep 21 '06 #1
6 1157

cr************@hotmail.com wrote:
I'm new to VS2005, I used VS2003 a bit, and I remember it didn't act
like this.

My code looks like :

try
{
blah
blah
blah
}
catch (Exception)
{
MyOwnException myoe = new MyOwnException ("Error on receiving data");
throw myoe;
}

And what I get when an error happens is a window telling me :
"Application1 has encountered a problem and needs to close.
Send Error Report Don't Send"

Then after clicking either "Send" or "Not Send", the windows closes and
the program vanishes.

As far as I remember I'm catching the exception and the program should
be keep working after that.

Where's my fault ?
You throw an exception from you catch block - where is that being
caught? In other words, it appears that the MyOwnException is not
beign caught.

--
Tom Shelton

Sep 21 '06 #2
<cr************@hotmail.comwrote:
I'm new to VS2005, I used VS2003 a bit, and I remember it didn't act
like this.

My code looks like :
<snip>
As far as I remember I'm catching the exception and the program should
be keep working after that.

Where's my fault ?
Well, you're throwing another exception after you've caught the
original one...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 21 '06 #3

I usually create a class, called

EntryPoint.cs
[STAThread]
static void Main(string[] args)
{
try
{

Application.Run(new Form1()); //Whatever your startup form is

}

}
catch (Exception ex)
{
//Notify User
MessageBox.Show( "A (uncaught) exception has occured. MyApp
cannot continue." );
//Shut down application
Application.Exit( );
}
}
This will catch any uncaught exceptions.

But Jon is right.
You catch an general exception, but you're rethrowing it.
Thus something else must catch it, or you'll get the blow-up screen.
You should should google

try catch finally brad abrams

and you can read where

"You should be writing many many more

try/finally
blocks

and not so many
try/catch/finally

blocks.

<cr************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
I'm new to VS2005, I used VS2003 a bit, and I remember it didn't act
like this.

My code looks like :

try
{
blah
blah
blah
}
catch (Exception)
{
MyOwnException myoe = new MyOwnException ("Error on receiving data");
throw myoe;
}

And what I get when an error happens is a window telling me :
"Application1 has encountered a problem and needs to close.
Send Error Report Don't Send"

Then after clicking either "Send" or "Not Send", the windows closes and
the program vanishes.

As far as I remember I'm catching the exception and the program should
be keep working after that.

Where's my fault ?

Sep 21 '06 #4

My complain is not why it is thrown, but why the application closes...
and I figured out why, but yet need to know how to workaround it.

The problem was this: it was on an thread.
If I run the same code without threading, the error is shown in a nicer
box with "Stop" and "Continue" buttons. Then the application doesn't
close on the error.

Now, the question, is it normal with a threaded application that a
thrown exception put the application down ?


sloan wrote:
I usually create a class, called

EntryPoint.cs
[STAThread]
static void Main(string[] args)
{
try
{

Application.Run(new Form1()); //Whatever your startup form is

}

}
catch (Exception ex)
{
//Notify User
MessageBox.Show( "A (uncaught) exception has occured. MyApp
cannot continue." );
//Shut down application
Application.Exit( );
}
}
This will catch any uncaught exceptions.

But Jon is right.
You catch an general exception, but you're rethrowing it.
Thus something else must catch it, or you'll get the blow-up screen.
You should should google

try catch finally brad abrams

and you can read where

"You should be writing many many more

try/finally
blocks

and not so many
try/catch/finally

blocks.

<cr************@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
I'm new to VS2005, I used VS2003 a bit, and I remember it didn't act
like this.

My code looks like :

try
{
blah
blah
blah
}
catch (Exception)
{
MyOwnException myoe = new MyOwnException ("Error on receiving data");
throw myoe;
}

And what I get when an error happens is a window telling me :
"Application1 has encountered a problem and needs to close.
Send Error Report Don't Send"

Then after clicking either "Send" or "Not Send", the windows closes and
the program vanishes.

As far as I remember I'm catching the exception and the program should
be keep working after that.

Where's my fault ?
Sep 21 '06 #5
Now, the question, is it normal with a threaded application that a
thrown exception put the application down ?
As of .NET 2 that is indeed the normal behaviour.
..NET 1 behaviour was to silently terminate the thread

You need to handle the exception in the thread

Cheers
Doug Forster
Sep 22 '06 #6
Ok, good to know, thanks a lot !

Doug Forster wrote:
Now, the question, is it normal with a threaded application that a
thrown exception put the application down ?

As of .NET 2 that is indeed the normal behaviour.
.NET 1 behaviour was to silently terminate the thread

You need to handle the exception in the thread

Cheers
Doug Forster
Sep 22 '06 #7

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

Similar topics

16
5266
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem...
21
2196
by: dkcpub | last post by:
I'm very new to Python, but I couldn't find anything in the docs or faq about this. And I fished around in the IDLE menus but didn't see anything. Is there a tool that can determine all the...
26
2853
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
6
2817
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
10
2720
by: Justin Dutoit | last post by:
Hey. I'm still not experienced at error handling, and I need to know if Try.. Catch blocks are meant to be used to handle errors in your own app, ie bugs. Or, are they only for external things like...
3
935
by: randy1200 | last post by:
I have a point in my code where I can get an exception if the network is not available. This exception is kind of ugly for the user to see. I'd like to catch and throw new exception that contains...
1
2368
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
0
6485
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...
6
4982
by: Chris Becke | last post by:
I *know* my CPU has opcodes that can do this - when adding (or subtracting) there is a carry flag that can be invoked to make the result essentially 1 bit longer than the data size used in...
0
7198
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
7072
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
7271
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
7319
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...
1
6979
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
7449
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
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.