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

I find the concept of unrecoverable panics extremely weird. Crashing your entire program just because something unexpected happened? Erlang would lime a word with you :)


This is not fair summary of the situation. Panics can be “caught”, most Rust web framework will catch panic when handling a http request and return 500, leaving other requests unaffected (more or less). This is almost no different from Python, Java, even Erlang.

Panic is a way for Rust library ecosystem to signal this error in un-recoverable, and is probably a bug in program, for which you would be happy getting Sentry or some such reporting.

Most errors in Rust are handled using mechanisms described in post using Result. Some, this is probably a bug in code, mechanism should be present in other languages.

There are even efforts to make code that can panic detectable at compile time, https://docs.rs/no-panic/latest/no_panic/


Not at all.

Recoverable errors -> Result/Option, i.e. have your types not lie and say "this function open_file() returns either Ok(file) or Err"

Unrecoverable errors -> panic, i.e. crash your program and present a stack trace for debugging


Well not every program has to be a super robust daemon recovering from any kind of problem.

There's a good bunch of programs that are just supposed to read some inputs, perform a task and crash with an error message and exit code if anything goes wrong.


> unrecoverable panics

Panics are recoverable.


FWIW, the article incorrectly but explicitly and repeatedly states that panics are not recoverable, and so this is a gripe with the content causing misinformation.


It’s not really a misconception exactly. They are to be used for unrecoverable errors, conceptually. Because of this, the ecosystem tends to treat them as such, even if you can choose to require the ability to catch them, just as if you can also require the ability not to catch them, which is one of the reasons why the ecosystem follows the rule: they can’t rely on the behavior (unless they want to limit their audience and that’s basically never worth it).


You cannot catch a panic, only an unwind. And you shouldn’t assume that your panic will unwind as a downstream user of your crate can just as easily change panics to aborts




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

Search: