Hi All,
Is it the right way of handling exception in a method?
Is it the right way of handling exception in a method?
Code:
public int DeleteFilesOlderThan(int days, int hrs, int mins)
{
string[] older = FilesOlderThan(Days, Hrs, Mins);
int count = 0;
foreach (string file in files)
{
try
{
File.Delete(file);
count++;
}
catch (Exception e)
{
Console.WriteLine("Unable to delete " + file);
Console.WriteLine("Reason: {0}", e);
//Console.WriteLine("Detected an exception!!!\n" + e );
}
Console.WriteLine("Files successfully deleted");
}
// presumably number of files deleted to be returned
return count;
}
Comment