4 ms·
I'm not very familiar with Go, so please correct me if I'm wrong, but this looks like this pattern was chosen due to the async-focused nature of the language; s
by akubera 10y ago
I'm not very familiar with Go, so please correct me if I'm wrong, but this looks like this pattern was chosen due to the async-focused nature of the language; similar to many callback-laden javascript error handling strategies. Is this true?
Also, I see that the error must implement the 'error' interface, and this interface specifies a single "Error" method. Is the typical error-checking practice to do type assertions on the err object, ensuring you know what went really went wrong?
I agree with the article that python's handling is better, if not for the fact that ignored errors within 3rd party libraries could go unnoticed and be hard to debug. Python3's try/except blocks even work in asynchronous coroutines.
Also, this article was written in 2012; this should be mentioned.
(previous discussion: https://news.ycombinator.com/item?id=4562211 https://news.ycombinator.com/item?id=4562211)
- ElKrist 10y agoI can't tell you why this pattern of error handling was chosen but this is different from the callback pattern in nodejs. In Go, errors are typically returned directly by the called function. Even if such function makes "asynchronous" calls (there is a great article shared on HN that explained why this term is not the best)