I can't remember when I last used a goto - but isn't this what you actually try to accomplish?
Public Sub Bypassfilenotfound()
Dim File2 As String = myScanPath.Text
Try
If My.Computer.FileSystem.FileExists(File2) = False Then
GoTo 1
End If
Catch ex As System.IO.FileNotFoundException
End Try
1:
End Sub
Not that I agree with the coding - it's fairly "unusual" , SAKryukov has a good point :)
As I don't program in VB, but find c# to my liking - I'd probably do it like this:
public static bool MyFileExists(string filename)
{
bool result = false;
try
{
result = System.IO.File.Exist(filename);
}
catch(Exception exc)
{
}
return result;
}
you should be able to use
MyFileExists
as a replacement for System.IO.File.Exist. If the function has any problems checking for the existence of the file it will return false. As I mention in the comments you should do something sensible about the exceptions - like logging.
You can use
log4net[
^] for this purpose.
The assumption is that you want the function to return
false
for filenames that you will not be able to use for further processing of the file.
The method will return true for files that are found, and false if they don't, or there was any problems with the
filename
.
The logic should be similar for VB ...
Regards
Espen Harlinn