sherifffruitfly said:
Good enough - I just typically shy away from "exception-based
programming", so I thought I'd see if there were another common way.
Thanks a bunch!
Considering that a file is a volatile object, I'm not sure you can avoid
using exceptions in any case, depending on what specifically you want to
do of course.
If all you want to do is to check the status of a file before attempting
to do something, then the state of that file might have changed from
your check to the point where you attempted your operation.
And besides, there's nothing wrong with using exceptions. As with all
things, there are areas where there are better constructs (depending on
the situation), but you should not strive to avoid something just
because of a feeling.
One of the places where I'd look at avoiding exceptions would be in a
very high volume transaction processing service, where perhaps the cost
of doing a few more if-statements would be far less than the cost of an
exception.
However, in the world occupied by a file system and a physical disk, I
don't think you should have to worry too much about the performance of
an occasional exception.