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:
- Compile with
panic=abort
, which makes all panics aborting. - 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.