Hi my dear fellow experts,
I am designing one function that must process files in the folder. The function must say how much files it has processed and also if there is error. What is best way to design such function? I am choosing between three choices:
bool ProcessFiles(out int fileCount)
{
// return true or false
}
int ProcessFiles()
{
// return -1 when failed
}
int ProcessFiles(out bool success)
{
// return count
}
Of course this example is rather an illustration to real life problems. I just want to elaborate good strategy.
I'd go for:
int ProcessFiles() // returns count
{
if(error)
{
throw new MyException();
}
}
i would go for
bool ProcessFiles(out int fileCount)
{
// return true or false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With