3 ms·
You can catch panics.
by edflsafoiewq 2y ago
You can catch panics.
- echelon 2y agoPanics are unexpected and not the preferred mechanism of error handling. Stick to Result<T,E>.
- edflsafoiewq 2y agoThe GP said > Users would rather see an error saying “whoopsie, maybe try that again later” than for the program to exit To achieve this, you need to catch panics. Rust does not use Result for things the OP is talking about like asserts.
- nicce 2y agoIf you want to handle the assert cases, you should not use the asserts in the first place.
- edflsafoiewq 2y agoThat isn't possible. The assert may not even be produced in code you control. The reason panics/exceptions exist is it is too onerous to handle every possible error condition at all callsites (allocation failure and broken pipes are the famous examples), and it is not possible to enumerate all possible error conditions (unintentional programmer errors for example). People have religious ideas about handling panics for some reason.
- echelon 2y agoPanics shouldn't exist in modern Rust (if there is such a thing) at all.
- edflsafoiewq 2y agoI take it you mean panics should always abort?
- aw1621107 2y agoI'm not sure that is something you can rely in general due to panic = abort, though to be fair that's more a concern for library developers since IIRC they don't control that particular setting.