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

You (learners of Rust) should also be aware that this is not, in the general case, true. Programs can be compiled to abort on panic, and that is a choice the compiling party makes, not the code author. There are also a lot of tricky caveats around catching panics that even experts get wrong.

It's applicable in niche circumstances, but don't get the impression that catching panics is something you should reach for lightly, or rely on always happening.

Hashed out previously in this thread and others.

3 Likes