473,656 Members | 2,983 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 :
"Applicatio n1 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 1163

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 :
"Applicatio n1 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.comwro te:
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.co m>
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.Exi t( );
}
}
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.comwro te in message
news:11******** **************@ e3g2000cwe.goog legroups.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 :
"Applicatio n1 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.Exi t( );
}
}
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.comwro te in message
news:11******** **************@ e3g2000cwe.goog legroups.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 :
"Applicatio n1 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
5279
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 is that when an exception is raised, the destruction of locals appears to be deferred to program exit. Am I missing something? Is this behaviour by design? If so, is there any reason for it? The only rationale I can think of is to speed up...
21
2220
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 exceptions that can be raised in a Python function, or in any of the functions it calls, etc.? /Dan
26
2887
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 belief is that checked exceptions should be required in .NET. I find that many others share the same views as I do. It is extremely frustrating to have to work around this with hacks like Abstract ADO.NET and CLRxLint (which still don't solve the...
6
2823
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 block, just in case there might be an exception? i.e. is it ok performance-wise to pepper pieces of code with try..catch..finally blocks that must be robust, in order that cleanup can be done correctly should there be an exception?
10
2735
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 db problems, file not found. Any websites or books on error handling, real-life examples, would be appreciated. Tks Justin Dutoit
3
939
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 only my error string and an OK button. If I say throw new System.Exception("The network is not available, the list will not contain data."), the user sees text they don't need to see, and they have to choose between break and continue buttons. ...
1
2377
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 look for when evaluating someone's code is a try/catch block. While it isn't a perfect indicator, exception handling is one of the few things that quickly speak about the quality of code. Within seconds you might discover that the code author...
0
6493
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 NullPointerException or ArrayIndexOutOfBoundsException. All of these extend the basic class Exception. In general, you can sort Exceptions into two groups: Checked and unchecked Exceptions. Checked Exceptions are checked by the compiler at compilation time. Most...
6
4990
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 calculations. When multiplying two numbers, the CPU automatically returns a double width result. c & c++ give programmers these bloody ridiculous integer types of undetermined size and no really optimal way to even build a variable width number library...
0
8296
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7310
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.