Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27358

VS 2008 error handling

$
0
0
I am trying to decide whether to use on error goto, or to use a try/catch/finally statement to catch errors. The problem I see with the try catch is that if you have say 400 lines of code, with lots of arrays in it, if you have the catch statement Like I got, how do I know which array caused the out of bounds exception? If I end up using the try catch, then I would like to be able to have statements that name each exception, vs Err.Number = 9 such as I have on the first one.
I found a site that listed all sorts of error numbers, but for some reason I can't find it again. There are some exceptions that I have found on different websites in System.IO. that do not come up for me when I type. Could this be because I haven't imported the right class or something like this?

Here is what I have found out so far by reading lots of stuff on the MSDN website:

Try
'put all my code here, the catch statements go at the end of the sub or the end of the section I am trying to catch an error in.
Catch A As Exception When Err.Number = 9 ' array out of bounds
'do stuff for array out of bounds
Catch B As System.InvalidCastException
'do something for cast exception
Catch C As System.NullReferenceException
'do whatever for Null Exception
Catch D As IO.IOException 'file not found
'do something for file not found
Finally

End Try

Viewing all articles
Browse latest Browse all 27358

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>