3 ms·
> There's no way to know which exceptions can be thrown from a function just by looking at its code, nor looking at the called-functions code. It's good you do
by wvenable 8y ago
> There's no way to know which exceptions can be thrown from a function just by looking at its code, nor looking at the called-functions code.
It's good you don't actually need to know that! And if you did, it wouldn't matter anyway because somebody could come along in the future and change that code that currently uses a database and change it a web service and all that knowledge would be wasted.
All you need to know is what exceptions you can handle and where you handle them. What error codes or exceptions each individual function everywhere up the call chain can raise is almost inconsequential.
- kaoD 8y ago> All you need to know is what exceptions you can handle Ah, so that's "all" I need to know! And that's what typed errors do.
- wvenable 8y agoYou might only be able to handle restartable network exceptions. In my case, that might be a single base type. So I put a try block in where I can handle that exception (where my network code starts) and I'm done. Do I need to check the return type of the thousands of methods that might make up that operation? Nope. Typed errors make me do a lot of work passing stuff around and declaring types that literally don't matter. If somebody adds a new method that does another network call, I'm still good and I didn't have to do anything.
- kaoD 8y agoYou like implicit. I don't. I don't think we can discuss deeper than that.
- wvenable 8y agoActually, for the most part I don't like implicit. But I also like encapsulation and polymorphism and you can't have those things if you are exposing implementation details all over the place. The other thing I don't like is pointless boilerplate code. But I do like strongly-typed languages and originally I thought I'd like checked exceptions before realizing just how wrong that concept is. It's not hard to see the parallels between checked exceptions and error returns.
- deleted 8y ago[deleted]