3 ms·
Absolutely not - the people who do that, don't understand the difference between refusal (precondition not met), and failure (unexpected system error). In your
by dawidloubser 11y ago
Absolutely not - the people who do that, don't understand the difference between refusal (precondition not met), and failure (unexpected system error). In your particular case above, I would never let IOException leak "up" into a client-facing contract.
How could I? I would have designed that interface long before implementing it. No, in that case, this is an unexpected system error - for example, an unchecked RuntimeException in Java.
Just because people don't know how to write software contracts properly, doesn't mean that languages and protocols should remove the notion of a checked exception.
When used properly, they are an essential part of an understandable contract. And that's before we even look at it from a type system point of view, where it's absolutely silly to use the same response message to represent either success of failure, greatly increasing the cognitive overhead of the developer calling your service.
- nbevans 11y agoYou need to learn more languages. "Checked exception" is highly Java-specific and it is biasing your understanding. A checked exception is okay but it is still an exception with all the stack frame capturing overhead that brings. In better languages like ML variants (say F#) we have discriminated unions. These let us return structured, type safe, result codes and information. Without all the overhead and OO-ness of nasty exceptions. We can still throw exceptions but these are strictly, and I mean strictly, for those very exceptional and unexpected scenarios.