logoalt Hacker News

Bratmonlast Tuesday at 7:12 PM3 repliesview on HN

Watching go people complaining about how other languages encourage bubbling errors up is always hilarious to me because there is literally nothing you can do with errors in go except bubble them up, log them, or swallow them.

Even the article considers "handling" an error to be synonymous with "Adding more text and bubbling it up"!


Replies

tail_exchangelast Tuesday at 7:48 PM

> there is literally nothing you can do with errors in go except bubble them up, log them, or swallow them

You can also add additional context to the error before bubbling it up. But yes, that part of the point. Instead of bubbling them up, the programmer should instead reflect on whether it is better than just log and proceed, or completely swallow them. This is what error handling is about.

Mawrlast Tuesday at 11:23 PM

I assume you mean languages with exceptions.

You can't bubble up an exception, it's done automatically. That's a very important distinction. You can't make the decision to bubble up or not, because you do not have the required information - you don't know whether an exception can be thrown or not at any point. Therefore, you can't say you're making a decision at all.

Explicit error allows you to be able to make the decision.

show 1 reply
gwdlast Tuesday at 7:26 PM

I mean, yeah, most of the time what you do is add more text and bubble up. But:

1. The very fact that adding more text isn't really any more verbose than not encourages you to add more text, making errors more informative.

2. A non-negligible amount of times you do something else: carry on, or do something specific based on what kind of error it was. For instance, ignore an error if it's in a certain class; or create the file if it didn't exist; and so on.

Forcing the error handling doesn't seem to me that different than forcing you to explicitly cast between (say) int and int64. Part of me is annoyed with that too, but then I have PTSD flashbacks from 20 years of C programming and appreciate it.

show 1 reply