Question Debugging first chance exceptions

Shaddix

Member
Joined
May 11, 2007
Messages
5
Programming Experience
Beginner
When running my program Visual Studio gives me a load of exceptions:

VB.NET:
A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
A first chance exception of type 'System.Exception' occurred in AutomaatVerhuur.exe
A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
A first chance exception of type 'System.Exception' occurred in AutomaatVerhuur.exe
A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
A first chance exception of type 'System.Exception' occurred in AutomaatVerhuur.exe
A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
A first chance exception of type 'System.Exception' occurred in AutomaatVerhuur.exe
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.NullReferenceException' occurred in AutomaatVerhuur.exe

the program runs fine, but it's a project for school so I have to solve these exceptions

I have option strict and option explicit both on, so I'm surprised I can run the program without any problem

is there an easy way to find the cause of such an exception? something to find the linenumber of the exception or something?

I'm using VS2008
 
thanks for that, but I'm still a bit confused
but my collegues from my class have to do the same project, and they do not encounter those exceptions, when I run their projects with my configuration it doesn't give those first chance exceptions
so I really got the feeling there is something that I can do better
 
I think you need to read up on exception handling in general. To me, the explanations in that article is clear water. Since your app runs "without any problem" these exceptions are caught by your code, ie no second chance exceptions. To put all code in a Try-Catch block is the wrong approach for exception handling, you have to give it a lot more thought than that. My initial approch to coding is to have no exception handling, the debugger will stop at any exception at the line that caused it, then you can find out what is the problem and maybe fix it. If the code itself can be fixed the change has made it more robust. Sometimes no logic fix can be applied, or the source of error can't be anticipated, or it isn't viable do anything about it; then you have an exception that you have to decide whether to handle right there, or let it pass and bubble further up the call stack. To handle it Try-Catch the appropriate code block (remaining code that depends upon the call that throws). If any code in the Try part fails the remaining code is never called, execution transfers to the Catch part. Here you can output error information if this is something user need to know. This is also a place where you can output debugging information about the exception, but remember the reason you got here in the first place was that you knew the exception could occur and chose to handle it.
 
Back
Top