Strange error - first chance exception

J. Scott Elblein

Well-known member
Joined
Dec 14, 2006
Messages
166
Location
Chicago
Programming Experience
10+
I am passing a ToolStripComboBox to a Sub in a module, using this as an argument, ByVal cbobx As ToolStripComboBox. When I step over this line in the debugger, using a Try/Catch :

VB.NET:
cbobx.Text = My.Settings.LastLogin

I get this error with console.writeline ex.message:

VB.NET:
A first chance exception of type 'System.NullReferenceException' occurred in BrowserControl.exe

LastLogin contains a string and is not null when I break on it before stepping over it, and the cbobox still gets filled with the correct text after stepping over it.

Anyone know why I might be getting the nullref exception?
 
All that message is telling you is that an exception was thrown somewhere. Exceptions are allowed to be thrown. It's when an exception is thrown and not caught that an application crashes. If your app keeps on going then obviously that exception was caught. As an example, if you do this:
VB.NET:
Dim reader As New StreamReader("This file does not exist")
then you app will crash with an unhandled exception. If you do this:
VB.NET:
Try
    Dim reader As New StreamReader("This file does not exist")
Catch

End Try
then the debugger will notify you that a first chance exception occurred, as it would for the previous code too, but it will continue to run because the chance was taken to handle that exception.
 
Back
Top