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

Cant catch an exception

Apologies if this is the wrong forum for this question.

Could anyone explain why this exception code is not working?

The exception is thrown, but then reported as unhandled. The try catch in
Main seems to be being ignored???

The exception being reported is a generic System.Exception, nothing exotic.

This is only an illustration by the way :)

public class A
{
Public void Bla()
{
if (something) { throw new Exception(“An Error”); }
}
}

public class B
{
static void Main()
{
// A collection of A's exists
foreach (A item in ACollection)
{
try
{
item.Bla();
}
catch
{
MessageBox.Show(“Caught”);
}
}
}
}

Any help much appreciated.

Jul 22 '05 #1
2 1513
Hi Tris ,
Have you tryed to change the catch with catch (Exception ex);
"Tris" <Tr**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
Apologies if this is the wrong forum for this question.

Could anyone explain why this exception code is not working?

The exception is thrown, but then reported as unhandled. The try catch in
Main seems to be being ignored???

The exception being reported is a generic System.Exception, nothing
exotic.

This is only an illustration by the way :)

public class A
{
Public void Bla()
{
if (something) { throw new Exception("An Error"); }
}
}

public class B
{
static void Main()
{
// A collection of A's exists
foreach (A item in ACollection)
{
try
{
item.Bla();
}
catch
{
MessageBox.Show("Caught");
}
}
}
}

Any help much appreciated.

Jul 22 '05 #2
Indeed I have. Unfortunatley, this makes no difference.

Thanks anyway!

Tris

"Nassos" wrote:
Hi Tris ,
Have you tryed to change the catch with catch (Exception ex);
"Tris" <Tr**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
Apologies if this is the wrong forum for this question.

Could anyone explain why this exception code is not working?

The exception is thrown, but then reported as unhandled. The try catch in
Main seems to be being ignored???

The exception being reported is a generic System.Exception, nothing
exotic.

This is only an illustration by the way :)

public class A
{
Public void Bla()
{
if (something) { throw new Exception("An Error"); }
}
}

public class B
{
static void Main()
{
// A collection of A's exists
foreach (A item in ACollection)
{
try
{
item.Bla();
}
catch
{
MessageBox.Show("Caught");
}
}
}
}

Any help much appreciated.


Jul 22 '05 #3

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

Similar topics

10
by: Gary.Hu | last post by:
I was trying to catch the Arithmetic exception, unsuccessfully. try{ int a = 0, b = 9; b = b / a; }catch(...){ cout << "arithmetic exception was catched!" << endl; } After ran the program,...
0
by: zee | last post by:
System.FormatException: Input string was not in a correct format. I am inputting into a databse the value that causes an error is a double, If I leave that field blank then I catch the exception it...
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
13
by: Benny | last post by:
Hi, I have something like this: try { // some code } catch // note - i am catching everything now {
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
3
by: will | last post by:
Hi all. I've got an question about how to catch an exception. In Page_Load, I place a DataGrid, dg1, into edit mode. This will call the method called GenericGridEvent. GenericGridEvent will call...
11
by: l.woods | last post by:
I want to set up my CATCH for a specific exception, but I really don't know which one of the multitude that it is. I am getting the exception now with Catch ex as Exception but I want to be...
2
by: Tris | last post by:
Apologies if this is the wrong forum for this question. Could anyone explain why this exception code is not working? The exception is thrown, but then reported as unhandled. The try catch in...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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 projectplanning, 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.