Lets say I have a function that should return me the information about all textfiles in a folder:
public static FileInfo[] GetTxtFiles()
{
//...
FileInfo[] files = directory.GetFiles("*.txt");
return files;
}
Thats fine. Now lets say the directory is empty or there are no .txt files or something like that, then I get an exception. I thought I could return a null if something goes wrong, something like this:
public static FileInfo[] GetTxtFiles()
{
try { //...
FileInfo[] files = directory.GetFiles("*.txt");
return files;
}
catch (Exception e)
{
logger.Error(e);
return null;
}
}
Now before I call this function I can always check
if (GetTxtFiles() != null) {
//do something
}
Is this alright? Or is it bad coding if Im returning null? Any suggestions? Thank you
