Question Need code(s)s to Catch specific IOException(s)

motoburn

Member
Joined
Jun 15, 2010
Messages
17
Location
Collinwood, TN
Programming Experience
Beginner
Does anyone know a link to a list of IOException codes or some way of catching a specific error?

I have been digging for a couple hours trying to find a code, or a number to catch when my app throws
VB.NET:
System.IO.IOException was unhandled
  Message="The file exists. "
  Source="mscorlib"

For this app, I am simply moving all files in specified directory to a directory on the file server. It is likely that a file being moved will already exist, in which case, I need to move the file to a different directory so it can be analyzed...

I am sure I could run
VB.NET:
 If File.Exists(...)=False Then
File.Move(...)
Else
File.move(..., somewhereElse)
end if
but I thought it would be cleaner in a Try/Catch block.

Should I just use the If/Then? I have used the MySqlException which has a number assigned to each exception, so I can catch duplicate keys and insert them into a temp table for analysis.... was hoping to do something similar here, but I can't seem to find any reference to System.IO.IOException's.. :confused:
I'm sure this is a simple noob question, but, there it is. Thanks for any help in advance

Chris
 
Use both:
VB.NET:
Try
  If Not File.Exists(...) Then
        File.Move(...) 'Could still error here
  Else
        Files.Move(elsewhere...) 'Could still error
  End If
Catch IOex As IOException
    'Code here
Catch ex As Exception
    'Generic code here
End Try
 
Back
Top