Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

An exception can be caught


A panic can be caught with catch_unwind. https://doc.rust-lang.org/std/panic/fn.catch_unwind.html


However you can set panic=abort in which case no unwinding takes place.

This makes panics completely unreliable for error reporting.


Eher 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


> 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.


When using panic=abort you can still report the error via the panic hook, you just can't recover from it.


A Rust panic can be caught, too.

It's just bad form to do so in Rust because it's bad for maintainability to design programs like that.

Rust is opinionated and very much NOT an anything goes language. There is a culture and the culture says do not catch panics. If you feel the need to catch a panic, make it a regular value instead.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: