No exception thrown?

  • Thread starter Thread starter Uchiha Jax
  • Start date Start date
U

Uchiha Jax

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?
 
Uchiha Jax said:
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 said:
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 said:
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?
 
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
 
Back
Top