4 ms·
The arguments I've heard against checked exceptions are that they're hard to compose. If you write the `send_mail` procedure you might only want it to throw `M
by kqr 10y ago
The arguments I've heard against checked exceptions are that they're hard to compose.
If you write the `send_mail` procedure you might only want it to throw `MailException`s of various kinds. But if you use a TCP procedure inside, you'll have to declare `send_mail` to also throw `ConnectionError`s, thus revealing its implementation. To correctly hide/abstract over the implementation, you have to internally catch any `ConnectionError`s thrown by the TCP procedure, and re-throw them as `MailException`s. That's a lot of manual work that shouldn't be needed.
Another similar problem is what someone else mentioned: if you don't actually know which specific exceptions your method can throw until runtime, what do you declare?
----
Note that this is also the case for some "null alternatives". Sure, the `Option`/`Maybe` type is easy to compose, but as soon as you start inserting error information in there (with an `Either` type) you run into some of the same problems. This is acknowledged by language communities where that is practised, and some of them prefer unchecked exceptions to `Either`-style types for that reason.
- aninhumer 10y agoIn your example, unless your send_mail procedure is generic over transport in some way, surely its use of TCP is an inherent part of its behaviour, not an implementation detail? You're going to have to handle them as TCP errors anyway, even if they're lifted to a different type, so why not just throw them as they are?
- ArkyBeagle 10y agoUnless there's a full discipline built into the system for addressing TCP errors that your "mail" thingy can rely on, you'll need to address it. And how can you not know the specific exceptions you need to handle? Don't you need to test all of those? I am sure you didn't mean it to, but this reminds me of meetings where people say "oh, we don't have to worry about that. TCP is reliable." Twitch :)