How to Panic in Rust

What exactly happens when you panic!() ? I recently spent a lot of time looking at the parts of the standard library concerned with this, and it turns out the answer is quite complicated! I have not been able to find docs explaining the high-level picture of panicking in Rust, so this feels worth writing down.

https://www.ralfj.de/blog/2019/11/25/how-to-panic-in-rust.html

I'd love to put this overview somewhere more permanently than a blog post, any suggestions for what would be a good place? I first through of the rustc guide but that is concerned with rustc, not libstd.

9 Likes

@RalfJung: Looks like we raced to write this explanation :smile: :https://github.com/rust-lang/rustc-guide/pull/521

7 Likes

Oh lol, sorry for that.^^ I felt the urge yesterday to write down this stuff, seems like it would have been a more productive use of my time to review your PR instead. :confused:

1 Like

Personally, I think your two contributions are complementary, so thank you both.

4 Likes