Panicking: Should you avoid it?

To my mind a panic is what happens when your program hits some erroneous condition that the programmer has failed to anticipate and handle. Basically a bug. Or something has happened that is bad and unavoidable, like running out of memory. At such a point your program is in an unknown state and the best thing to do is bail out immediately rather than try and limp along in a broken and unpredictable way.

You may like to read this lengthy discussion of panic Negative views on Rust: panicking

3 Likes