4 ms·
Go's errors are really nice (if a bit repetitive) in my opinion. Type signatures enforce that you accept and acknowledge an error returned from an invocation, b
by imsofuture 9y ago
Go's errors are really nice (if a bit repetitive) in my opinion. Type signatures enforce that you accept and acknowledge an error returned from an invocation, but leave it up to you to handle, pass along, or silently swallow.
- acdha 9y agoDoes that mean it now throws an error if you use the common punt like `foo, _ := …` and never check `_`?
- imsofuture 9y agoNo, but that's what I mean as intentionally ignoring.
- growse 9y agoNo, because using `foo, _` you're explicitly saying that you don't care about the error.
- hdhzy 9y agoSo... Just like checked exceptions in Java?
- imsofuture 9y agoYes, it's somewhat similar in that the compiler checks if you have handled or chosen not to handle an error. You're not allowed to ignore it (through omission).
- baq 9y agoyeah but better because you don't break the world if you add a new exception to a public method.
- concede_pluto 9y agoDeclaring that every method throws Exception doesn't break the world any more than every Go function returning an argument of type error. You're intentionally saying pretty much anything could go wrong and nobody can plan ways to recover.