3 ms·
> unwrap [...] causes application level crashes in way that is very much easier to avoid in other languages Unwrap does what just about every other language wi
by jjnoakes 9y ago
> unwrap [...] causes application level crashes in way that is very much easier to avoid in other languages
Unwrap does what just about every other language with exceptions-by-default does: it prints out a message for developers and exits. If you don't want that behavior, that's fine; in Rust you'd not use unwrap(), and in other languages you'd catch the exception.
Now, I agree that if you are using a library which does unwrap() in Rust vs a library that throws an exception in Python, you have different situations. But unwrap() isn't meant to be used in libraries (or if it is, only for fatal errors which should be uncatchable).
> Whats (sic) your justification for unwrap? I've never seen a meaningful justification for it other than not wanting to handle errors properly.
That is the justification for it: you are writing a simple short script-like tool (or you are prototyping or exploring some problem through one-off or throw-away code) and you want any errors to immediately exit with a developer-centric message and failure code. unwrap() is perfect for this.
It's the same justification for not catching every exception in other languages. Sometimes you are fine with an error printing a message and exiting.