3 ms·
All components can fail; even if just by programmer error. There is a difference between expected failures and unexpected failures. I like to use the example
by wvenable 9y ago
All components can fail; even if just by programmer error.
There is a difference between expected failures and unexpected failures. I like to use the example of int.Parse() and int.TryParse() in C#. These functions do exactly the same thing but treat errors very differently. You use int.Parse() when you expect the parse to always succeed. It will raise an exception if the parse fails. int.TryParse() doesn't raise an exception, it returns a boolean and you use it when you expect the parse to fail.
Returning a boolean indicating success/failure can be part of the API contract with well defined semantics. But that can't help you with unexpected errors that are part of the implementation.
For unexpected failures, you want to know the cause of it and you want as much implementation detail as possible.
I can't recover from a missing file, but I can recover from temporary network problems. If the file is missing, I want to know what file is missing so I can fix that manually.