Panics

Rust will trigger a panic if a fatal error happens at runtime:

  1. fn main() {
  2. let v = vec![10, 20, 30];
  3. println!("v[100]: {}", v[100]);
  4. }
  • Panics are for unrecoverable and unexpected errors.
    • Panics are symptoms of bugs in the program.
  • Use non-panicking APIs (such as Vec::get) if crashing is not acceptable.