Which one should I use? panic! vs. unreachable!

They can sometimes be handled. As per the docs on catch_unwind, it only catches "unwinding" panics, but you can also have aborting panics which cannot be handled.

Currently, there are two ways to get aborting panics:

  1. Compile with panic=abort, which makes all panics aborting.
  2. Call std::panic::always_abort which makes any future panics aborting panics.

Additionally, a panic hook set by set_hook can take action before the panic runtime has a chance to run. If it exits (as that playground example does), then your catch_unwind never returns. It could also loop forever, again stopping you catching the panic.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.