473,386 Members | 1,598 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,386 software developers and data experts.

No exception thrown?

I had a bug, code kept stopping without any warning.
I'd put a breakpoint on say line 3 and line 8. 3 would trigger but the
breakpoint on line 8 would never trigger.
After trying a few things I figured an exception must be happening and tried
it within a try catch, true enough I got an exception.
This confuses me, I always thought that if an unhandled exception occured
the program would crash out informing me of the problem rather than
continuing but not running properly.

The code that was causing the exception was this silly method:

public ArrayList GetRatings(ArrayList users, Rating.RatingType rType, int
id)
{
ArrayList ratings = new ArrayList();

foreach(RatingRow rRow in Rating.Rows)
{
if(rRow.RatingType == Convert.ToInt32(rType) && rRow.RatedID == id)
{
ratings.Add(rRow);
}
}
foreach(User u in users)
{
foreach(RatingRow rRow in ratings)
{
ratings.Add(CreateRating(rRow)); //// Enumeration exception here
}
}
return ratings;
}
Is there any reason why the program would not crash out when this exception
occured and wasn't handled?
Nov 17 '05 #1
4 3004
Uchiha Jax <i_************************@NOSPAMhotmail.com> wrote:
I had a bug, code kept stopping without any warning.
I'd put a breakpoint on say line 3 and line 8. 3 would trigger but the
breakpoint on line 8 would never trigger.
After trying a few things I figured an exception must be happening and tried
it within a try catch, true enough I got an exception.
This confuses me, I always thought that if an unhandled exception occured
the program would crash out informing me of the problem rather than
continuing but not running properly.


No - it will do that in the main thread, but not in threads you
explicitly created or thread pool threads. However, you can rectify
that by adding a handler for the AppDomain.UnhandledException event.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Jon Skeet [C# MVP] wrote:
No - it will do that in the main thread, but not in threads you
explicitly created or thread pool threads. However, you can rectify
that by adding a handler for the AppDomain.UnhandledException event.


AppDomain.UnhandledException doesn't seem to always work for me in GUI.
I'm guessing some of the code invoking event's silently swallows exceptions.

I'll try to remember to follow-up with an example next time i see it.

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #3
Helge Jensen <he**********@slog.dk> wrote:
Jon Skeet [C# MVP] wrote:
No - it will do that in the main thread, but not in threads you
explicitly created or thread pool threads. However, you can rectify
that by adding a handler for the AppDomain.UnhandledException event.


AppDomain.UnhandledException doesn't seem to always work for me in GUI.
I'm guessing some of the code invoking event's silently swallows exceptions.

I'll try to remember to follow-up with an example next time i see it.


Well, there's the Application.ThreadException event to subscribe to for
GUI threads - perhaps that's what you're after?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Thanks for the replies!
The event that was firing was from the MediaPlayer control, I didn't
explicitly create a new thread so i'd assume the Media Player control is
using the Thread Pool then.

Thank you for the tips on AppDomain.UnhandledException that's going to be of
great use to me in the future.

Kind Regards
Jax
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Helge Jensen <he**********@slog.dk> wrote:
Jon Skeet [C# MVP] wrote:
No - it will do that in the main thread, but not in threads you
explicitly created or thread pool threads. However, you can rectify
that by adding a handler for the AppDomain.UnhandledException event.


AppDomain.UnhandledException doesn't seem to always work for me in GUI.
I'm guessing some of the code invoking event's silently swallows exceptions.
I'll try to remember to follow-up with an example next time i see it.


Well, there's the Application.ThreadException event to subscribe to for
GUI threads - perhaps that's what you're after?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #5

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,...
42
by: cody | last post by:
public DateTime Value { get { try { return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text), int.Parse(tbDay.Text)); } catch (FormatException)
6
by: Páll Ólafsson | last post by:
Hi I have a problem with the Microsoft.ApplicationBlocks.ExceptionManagement? I can't get it to work in RELEASE mode? If I run the project in debug mode the block works fine but when I run the...
5
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() {...
4
by: Bhavya Shah | last post by:
Hello, I am facing a very strange problem in my application. I have a form on which I select a path. I open the FolderBrowserDialog for path selection. Once the path is selected I press a button...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
3
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own...
132
by: Zorro | last post by:
The simplicity of stack unraveling of C++ is not without defective consequences. The following article points to C++ examples showing the defects. An engineer aware of defects can avoid...
7
by: Keith Halligan | last post by:
I'm a bit unsure about exception specifications and the rules that they enforce. I've had a look at the C++ spec and it doesn't state about the errors that it enforces, if an exception is thrown...
7
by: Ralf Jansen | last post by:
For logging purposes i want to determine if the current executing code is running in an ~exceptionhandling context~. I need no details about the exception just if an exception has been thrown and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.