I have a vector which contains a list of files to open and parse, and I was wondering what is the best choice to do in my case.
This what I started to do :
for (int i =0 ; i< files.size() ; i++)
{
System.out.println("n°" + i + " : " + files.elementAt(i));
try
{
// open the files
}
catch (Exception e) {
// TODO: handle exception
}
}
or what do you think about this one?
try
{
for (int i =0 ; i< files.size() ; i++)
{
System.out.println("n°" + i + " : " + files.elementAt(i));
// open the files
}
}
catch (Exception e) {
// TODO: handle exception
}
EDIT:
My purpose is that, when I try to open a file that doesn’t exist I must throw something or maybe write the exception in a log file and continue opening the other files.
So I think the first solution is the best in my situation?
I would go with the first one – that way in case file 7 is corrupt for instance, you can still get the data from 8-10 (or whatever). And even if they are all corrupt, you don’t lose anything.
I suppose it would come down to how your application should work. If one file being wrong will bring the whole thing to a screeching halt, the second is more appropriate, but generally I have found the first to be more useful.