3 ms·
A panic can be caught with catch_unwind. https://doc.rust-lang.org/std/panic/fn.catch_unwind.html https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
by CodesInChaos 4y ago
A panic can be caught with catch_unwind. https://doc.rust-lang.org/std/panic/fn.catch_unwind.html https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
- masklinn 4y agoHowever you can set panic=abort in which case no unwinding takes place. This makes panics completely unreliable for error reporting.
- wongarsu 4y agoEher depends on what you want from an exceptions mechanism. There has always been a debate what exceptions are for. Python leans heavily towards "exceptions don't have to be exceptional, they can be normal control flow", while Rust is in the other side of the spectrum closer to "if it's something you might want to handle it's not exceptional enough to be an exception". Java is somewhere in between. All of them are valid view points. A language without reliable exception mechanism is C, where even the most unusual errors are communicated through return codes or global flags that you are expected to check manually
- masklinn 4y ago> Eher depends on what you want from an exceptions mechanism. Not really. If it instantly terminates the program without recourse, it's not an exception system: by definition, exceptions come with exception-handling of some sort.
- CodesInChaos 4y agoWhen using panic=abort you can still report the error via the panic hook, you just can't recover from it.