Unexpected Behaviour on Error

rbulph

Junior Contributor
Joined
Feb 17, 2003
Messages
397
Normally if there's an error in my code the debugger stops at that error and tells me about it. But a recent null reference error in a sub called from the Paint event of a Picture box did not cause the debugger to stop execution but to abort the drawing and colour the picturebox white with a red border and red diagonal lines. The following message appeared in the Immediate Window:

"A first chance exception of type 'System.NullReferenceException' occurred in Res Ipsa.exe"

This really threw me as I originally thought that somehow I was drawing this pattern. But anyway does anyone know why it did this rather than stop execution in the normal way?
 
Sounds like you are passing something into the PictureBox's paint method either directly or indirectly that it either doesn't expect or doesn't want and the PictureBox is throwing an exception that you aren't handling. Because the exception is thrown from so far down the call chain from within the Framework, you get errors that are a little different than errors caused directly by you, say in your form or something. Don't get me wrong, you are still causing the error, it's just not happening until later.

Could you post up some code around where the error occurs?
 
Back
Top