O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Error Handling

In this chapter, we'll take a look at how unexpected situations are handled in Rust. Rust's error handling is based on generic types, such as Option and Result, which we saw in the previous chapter. There's also a mechanism called panicking, which is similar to exceptions, but unlike exceptions in other languages, panics are not used for recoverable error conditions.

The topics covered in this chapter include:

  • The Option and Result types
  • Matching against the Option and Result types
  • Helper methods for handling errors
  • The try! macro
  • The ? operator
  • Panics
  • Custom errors and the Error trait

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required