3 ms·
catch_unwind Exceptions, at last! Not very good exceptions, though. About at the level of Go's "recover()". If this is done right, so that locks unlock, dest
by Animats 11y ago
catch_unwind
Exceptions, at last! Not very good exceptions, though. About at the level of Go's "recover()". If this is done right, so that locks unlock, destructors run, and reference counts are updated, it's all the complexity of exceptions for some of the benefits.
I'd rather have real exceptions than sort-of exceptions.
- vvanders 11y agoSo much snark. Error handling is something Rust does really well. Having used exception languages quite a bit I much prefer the forced handled return values. Exceptions don't map well to the type of handling patterns like and_then(...), or_else(...) and the like which I find much more ergonomic and clean.
- valarauca1 11y agoExceptions can also be a pain to deal with in lazy Iterators. Either every lambda needs to be a try statement, or you need state.
- deleted 11y ago[deleted]
- tatterdemalion 11y agoUsers are strongly and emphatically discouraged from using this for expection-style control flow. This is for managing crashes at the thread or FFI boundary. In general, we're very happy with monadic error handling and don't want exceptions.
- steveklabnik 11y agoThese are not exceptions, and are not intended to be used like exceptions. They may have an implementation that's kinda sorta similar to exceptions, but that doesn't make them exceptions.
- kibwen 11y agoThese are not exceptions, and I guarantee that you and your users will be very, very miserable if you try to use them as such. :P This is primarily for preventing undefined behavior at FFI boundaries, there are no affordances in the language that make this mechanism anywhere comparable to a real exceptions system from, say, Python.
- MichaelGG 11y agoI must say I came into Rust and didn't like the lack of exceptions - and these still aren't. The community explained it to me, and now I'm noticing more cases in other code (C,C#) where the forced error code system (handle or panic) would be far superior. Having it at the thread boundary is good enough so you can write, say, a webserver, without letting user code or a mishandled request killing the process.