|
-
Jul 5th, 2006, 03:20 AM
#1
Thread Starter
Hyperactive Member
[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
-
Jul 5th, 2006, 03:38 AM
#2
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.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jul 5th, 2006, 03:50 AM
#3
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:
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.
-
Jul 5th, 2006, 03:54 AM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|