Sign in to follow this  
TomCatFort

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

Recommended Posts

TomCatFort    133
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
ernow    732
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this