4 ms·
Except that the caller can't tell what failed - was it file.Open, or was it callFunctionThatMightErrorOut? They both just cause the same FailedToReadConfigFile
by NateDad 12y ago
Except that the caller can't tell what failed - was it file.Open, or was it callFunctionThatMightErrorOut? They both just cause the same FailedToReadConfigFileException, so you've made it impossible for the caller to react differently to each failure. In addition, they may even throw the same type of error (FileNotFoundException, for example), which may make it hard even for a human looking at the error to understand what actually failed, without looking at the stack trace and going into the code (which should be a last resort).
- dragonwriter 12y ago> Except that the caller can't tell what failed - was it file.Open, or was it callFunctionThatMightErrorOut? The caller knows that the function they called failed, and has as much detail from the underlying error as it makes sense to include in the special case Exception constructed from it. > They both just cause the same FailedToReadConfigFileException No, they cause the same class of exception. The data in that Exception can vary as much as necessary based on the data in the underlying exceptions thrown. Yes, if you actually have a need to differentiate, you may need additional try/catches, but that's usually a violation of encapsulation that exposes internal implementation details of a method to calling code, which defeats much of the purpose of OO, or even merely structured, programming.