3 ms·
If it doesn't return an error code, nor throw an exception, how do you know why it failed? Man, the resistance to exceptions with their human-readable error me
by throwaway2037 2y ago
If it doesn't return an error code, nor throw an exception, how do you know why it failed? Man, the resistance to exceptions with their human-readable error messages and stack traces and sorely misunderstood on HN. Any time someone says "exception", 50 people show up to point at the boogey man. Why all the fear? I grew up programming in the era of "errno only" (or god forbid: Win32's GetLastError()). It was awful. Exceptions are so much more human-friendly. Most programmers are writing CRUD apps for a business. Exceptions are terrific for this case.
- mrkeen 2y ago> Man, the resistance to exceptions with their human-readable error messages and stack traces and sorely misunderstood on HN. You grew up with "errno only", so that's your frame of reference. You've seen exceptions and don't want to go back to errno. Do you "fear" errno? Is errno the "boogey man"? I've seen monadic error handling and I don't want to go back to exceptions.
- tredre3 2y agoThere's a range of other options for error handling between a global errno and wrapping every lines in try-catch... Many languages make it idiomatic for functions to return a value or error (Rust, Go, modern C++) so that you can access a human-friendly error on failure. https://doc.rust-lang.org/std/result/ https://doc.rust-lang.org/std/result/ https://go.dev/doc/tutorial/handle-errors https://go.dev/doc/tutorial/handle-errors https://en.cppreference.com/w/cpp/utility/expected https://en.cppreference.com/w/cpp/utility/expected (there's also std::variant and std::optional that can get you there since C++17)
- kaba0 2y agoGo pretty much uses a global errno, it’s literally analogous, and is a terrible language from an error handling perspective, that failed to learn anything since C.