views:

882

answers:

4

Good evening, everyone;

My name is Braden and I'm using Visual Basic 2008 Express Edition.

I've been running through the MSDN help documents to get a hang of Visual Basic. After trying out the example using timers --one drags a label and timer component into the designer and adds the following to the components subroutine

Label1.Text = My.Computer.Clock.LocalTime.ToLongTimeString

The output for the immediate window during debug is the following

A first chance exception of type 'System.InvalidCastException' occured in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occured in Microsoft.VisualBasic.dll

The same error occurs on a previous MSDN example using a context menu component. Should I Try...Catch...Finally this error and try to move on? Or, am I dealing with something much more serious?

Be gentle, I'm new. \:-|

A: 

In the Debug menu -> Exceptions, you can enable the debugger to stop when an Exception is first thrown, even if it would be caught later; if you want to find out what's happening, this is the easiest way to do it

Paul Betts
A: 

In the first chance exception examine the details of the exception. You should see a stack frame/trace property. In there you should see what line the error occurs on. This should help you.

Preet Sangha
+1  A: 

When you see something about a first chance exception, it only means that an exception was caught within the code you called but does not necessarily mean that the code failed. If the code runs without causing your program to crash and returns a valid value, then do not have a problem. You will also see output in the debug window about first chance exceptions when you implement your own try/catch blocks.

Zach Johnson
A: 

In the IDE try going to Tools > Options > Projects and Solutions > VB Defaults and setting Option Strict to 'On' - this may help catch casting problems when you compile your project rather than when you run it.

A 'first chance execption' does not necessarily mean you have a problem in your code. It could mean the IDE or the compiler or any other involved component encountered and handled an error and in the process the debugger is notified and the exception is being reported to the immediate window. This is an excellent post on the topic:

http://blogs.msdn.com/davidklinems/archive/2005/07/12/438061.aspx

Gary.Ray