5 ms·
In Go there are two ways you can handle wrong things happening: - return an error - panic What is the recommended, best, pretty, beautiful way? Return an
by fiatjaf 9y ago
In Go there are two ways you can handle wrong things happening:
- return an error
- panic
What is the recommended, best, pretty, beautiful way? Return an error. Nobody uses panic.
Javascript Promises are equivalent to that.
If you want to stop the main program, call process.exit(). That would be the equivalent of panic.
- codedokode 9y agoI don't think it is beautiful. This fills program with lots of unnecessary `if`s for checking results of each call. Also, it prevents one from chaining functions like a(b(x)).
- fiatjaf 9y agoYeah, you're right. Not beautiful and prevents chaining. But works like a charm, don't you think? Chaining functions is for functional people. Go is proudly imperative.