I have a function that checks if a path exist with parameter throwExceptionIfOffline which throws an exception if path doesn't exist because sometimes I want the calling function to exit right away (via try catch) if that is the case. Other times I want the calling function to keep going so I return false.
Is this a bad design decision and should I always return true or false and handle the exit logic in the calling function?
This is mostly to check if network drive is online.
public bool CheckPathValid(string fullFilePath, int maxTimeMillisecond, bool throwExceptionIfOffline)
some way im using this Exception:
try {
CheckPathValid(@"\\somepath", 1000, true);
//more code i want to skip....
} catch (Exception) {
Log("func1 failed due to path not existing.");
}
return false:
try {
foreach (path in somepathlist) {
CheckPathValid(@"\\somepath", 1000, false); // fails go to next path
}
} catch (Exception) {
Log("func1 failed due to path not existing.");
}
Aucun commentaire:
Enregistrer un commentaire