Determining a Network Error from an IOException

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We have a loop where we process a large number of files.

We need a way to make a distinction between the following two IOExceptions Messages:
1. The network path was not found.
2. The process cannot access the file "\\NetworkPath\FileName" because it is being used by another process.

In the first case we have a network connection problem and their is no need to continue the loop.
In the second case we simply need to skip that file and continue with the next.

Is their a way to make this distinction without resorting to examining the Message string?

TIA
 
Jay:

AFAIK, you need to examine exception's info to make distinctions in general
within exceptions of the same type... However, you can check for
Directory.Exists to eliminate the first one...
if(Directory.Exists(@\\NetworkPath){
//try accessing the file.

}

If you do this check in the first place, then you can't throw a not found
exception so even though you're not technically drawing a programmatic
distinction, I think the end result is what you want.

HTH,

Bill
Jay Pondy said:
We have a loop where we process a large number of files.

We need a way to make a distinction between the following two IOExceptions Messages:
1. The network path was not found.
2. The process cannot access the file "\\NetworkPath\FileName" because
it is being used by another process.
 
Back
Top