Your strategy, in a case like this,
may depend on what type of errors you anticipate you need to handle, and your potential need to evaluate the results of executing this method.
I can assure you this code ...
at run-time ... without any try/catch ... has potentially one source of errors: your calling it with an invalid Directory name.
You could handle that by testing whether the Directory exists at the start of the method:
if (! Directory.Exists(sDir))
{
Log("System.IO.DirectoryNotFoundException " + "... Directory does not exist");
return null;
}
Or, you could "get fancy" and throw an error there ... handling it in a 'catch block.
Once the method returns, you can test it like this:
ArrayList ConfigFiles = FileSearch(theFilePath, theFileSpec);
if (!(ConfigFiles == null || ConfigFiles.Count == 0))
{
}
Or, you could take different actions depending on whether there was an error (null returned) or a zero result count.
However, I'm not trying to "talk you out of" using a try/catch block: I'm just trying to contribute to your awareness of your choices !
Suppose some error (cosmic rays, hackers) did occur while executing the code that scans the list of Directories and "harvests" their files that match your specification: in that case you
might have a valid set of partial results: if you return null on an error, you will "throw away" any partial results. If you return the ArrayList on an error, in that case, you could use any partial results.
The choice is yours.