Hacker News new | ask | show | jobs
by nulld3v 1508 days ago
The assertion remains true though. Unwrap should only be used if you are prototyping or you are 100% sure it will never actually panic.

It's just like the IndexOutOfBounds exception in Java. Many functions can theoretically throw it, but most libraries and programs do not catch it because usually if it is thrown it means that something happened that the programmer did not expect and therefore the program should crash.

1 comments

There's a difference between what you should do and what people actually do. If a lot of them use unwrap in production, then OP's argument is valid.
The problem would not be that it is commonly used, the problem would be that it is abused. And I don't see that happening currently.

The assertion that "If a library panics on user data, that's a pretty serious bug" remains true.

If a library is panicking on invalid user data, it is because they are abusing panic, which is a serious bug. Or they just didn't realize that their code could panic, which is also a serious bug.