3 ms·
> At its core, compilers offer a flag that lets you turn them off, same as Rust. That is true and in embedded projects it is common that exceptions are forbidd
by weinzierl 6y ago
> At its core, compilers offer a flag that lets you turn them off, same as Rust.
That is true and in embedded projects it is common that exceptions are forbidden, which shocks many young developers who are not used to write C++ without exceptions;-) In C++ it's nice when you have exceptions but without them you are very much on you're own, almost as you were writing C. Additionally every library does error handling slightly differently and you quickly end up in a world of pain.
The really nice thing about Rust, in that regard, is that there is no need for different error handling systems. No matter if you are writing very low level code (e.g. embedded systems) or high level (e.g. web apps) code the basic error handling primitives are the same. Since we have the question mark operator the ergonomics are not too different from exceptions in other languages. What is not so clear at the moment is, what the best practices are on how to combine these primitives. As far as I understand this is one of the major areas the Error Handling Group is to address.
- saurik 6y agoHaving to throw ?s and unwraps on what amounts to essentially every single function call--as if you think your function can't fail you probably didn't think through what it does very well--is kind of ridiculous, though: good systems avoid error "handling" (so you never look at errors) and centralize error management and recovery (so you want error routing, which exceptions can do). Even Erlang and Haskell (yes, in addition to monads) have exceptions, and languages with true "monadic" error handling (which some claim Rust has, but it doesn't) manage to hide it all behind their monad application syntax. Rust has taken a "worst of all worlds" approach here, mixing all of poor performance, poor ergonomics, and poor functionality together to get their current error handling solution :(.
- dralley 6y agoThat is very much an opinion. It's very useful to know exactly which lines might be throwing an error. And I don't agree that "essentially every single function call" needs a ? or an unwrap(), that has not been my experience at all.