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.
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.