[2005] A first chance exception of type 'System.InvalidCastException' occurred
Sometimes, my program generates this kind of exception:
A first chance exception of type 'System......Exception' occurred in MyCode.exe
The program does not stop because of it, only shows this exception in debug window. So, I'm not sure where this happened. Is there a way to force the vb express 2005 stop when this exception is happening?
It seems the program runs like what I want, but this exception worrys me.
thanks
bear
Re: [2005] A first chance exception of type 'System.InvalidCastException' occurred
So that means you are executing the code using the IDE. Why would you want VBE 2005 to stop when this exception is occuring?
The better way of handling this would be to use Exception Handling (Try..Catch..Finally..End try). If you can show us the code which is throing this exception then probably people here will suggest how to do exception handling in your case.
Re: [2005] A first chance exception of type 'System.InvalidCastException' occurred
When the IDE says that a first chance exception occurred it means that an exception was thrown. If the IDE doesn't break that means that the exception was caught and dealt with, so there's no issue. Try running this code:
VB Code:
Try
IO.File.Open("This file does not exist.", IO.FileMode.Open)
Catch ex As Exception
End Try
and you'll get this output:
Quote:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
but there's no need to worry because you've handled the exception.
Re: [2005] A first chance exception of type 'System.InvalidCastException' occurred
In addition, while they should be avoided if possible, exceptions are a quite legitimate part of program execution. It's their going unhandled that is a real issue, because that means crashy, crashy.