views:

295

answers:

2

I am rendering stuff with a Graphics-object in a picturebox inside the Paint-event for that picturebox.

    void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        g.FillEllipse(color, x, ...);
        etc etc......
    }

Everything works fine but suddenly the picturebox turns white and displays a big red X. If i look in the output-window I can see that there is an exception there, often an OverflowException or NullPointerException.

Is there any way to find from where that exception came? The debugger doesn't break like it does everywhere else when you get an exception.

+2  A: 

You can tell the debugger in visual studio to break on all exceptions, or which exceptions to break on even if they're user-handled.

EDIT: in the menus it's Debug -> Exceptions... -> check the "Thrown" box.

McAden
Thanks, that option really should be default for every exception.
Not if you expect to handle the exception. For example I recently did an automated parsing of PDFs using PDFBox. PDFBox throws an exception if it encounters a password-protected pdf it can't open. I don't want the debugger to halt every time it hits this error so it's in a try/catch block that logs and goes on about it's business. I wouldn't want the debugger to ignore the catch and break.
McAden
A: 

This isn't the doing of GDI+. This is the designer keeping Visual Studio from crashing. Is this an error that is only occurring at design time? What if you try to reproduce it at run time?

Snarfblam
It is at run time i get the error.
Oh, I see. I've only ever run into this in the designer.
Snarfblam