Jump to content
  • Advertisement
Sign in to follow this  
TomCatFort

[.net] Stop Application.Run() catch exceptions or make debugger break.

This topic is 2732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I did some research and learned that Application.Run has an exception handler, but it's supposed to made in a way that if a debugger is attached, the debugger breaks and you can see where is the unhandled exception thrown. I have a Form and I override OnClientSizeChanged method, and I throw an exception in it. Then it happens as I expected, the debugger breaks and locate the throw. But here comes my problem: I also overrided the OnPaint and OnPaintBackground methods, but if I throw an exception in it, the debugger wont break, and I can not get to the exception. And this is a huge problem as there will be a huge amount of code there. I throwed Exception instances in both cases. I also played with the thread exception event and the related method Application.SetUnhandledExceptionMode() but without any good result.

How do I make my debugger breaks in OnPaint? I'm using VS2010 and .NET v2.0.


----------------------CODE----------------------
void Main(string [] args)
{
Application.Run(new MainForm());
}

override void MainForm.OnPaint(EventArgs ea)
{
throw new Exception(); //Does not break while debugging.
...
}

override void MainFormOnClientSizeChanged(EventArgs e)
{
throw new Exception(); //Debugger breaks.
...
}

Share this post


Link to post
Share on other sites
Advertisement
Debugger.Break() might do the trick.

Debugging paint events is hard, IMHO: I never debug such events but use Debug.WriteLine(...) or Trace.WriteLine(...) in the event so focus and repainting is not interupted.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!