News for hackers. Stuff that matters.
Re:Elegant Error Handling with the JavaScript “Either” Monad by roblabla on Wednesday June 19, 2019 @08:37AM (#20222716)
I'm not familiar with Haskell, but Rust's `Result` type is the same idea, and I wouldn't want to trade it for try-catch. It supports backtraces[0], has a simple way to turn errors into a "catch-all" type[1], but it is significantly less complex since it reuses the basic return value mechanism a function has.

If you want to exit the program because the error can't be handled (similar to an unhandled exception), rust has a different concept for it, panics, and any Result can be turned into a panic via `unwrap()`.

IMO both are important: panics represent unrecoverable errors, while Results can be acted upon (for instance, if read() returns Err(EINTR), you'll want to retry the read)

[0]: Granted, you need to write some boilerplate to get the backtrace on error creation.

[1]: You can cast all errors to `Box<dyn Error>`, a heap-allocated dynamically dispatched Error type.

Re:Elegant Error Handling with the JavaScript “Either” Monad by kmonsen on Wednesday June 19, 2019 @08:54AM (#20222820)
So in rust you write with result and in js you use try/catch. Pretty simple, and readers will understand the code.
Re:Elegant Error Handling with the JavaScript “Either” Monad by roblabla on Wednesday June 19, 2019 @10:33AM (#20223696)
Oh I agree, and definitely don't recommend using Result in JS, the language is just not tailored for it. I was specifically addressing

> I never understood the love for Either-based error handling in Haskell and other languages.