In Rust, errors are handled through two types of errors: recoverable and unrecoverable.
While unrecoverable errors are usually the result of a bug in the program and cause the program to panic, recoverable errors allow the program to gracefully handle the error and continue executing.
In this video, we’ll dive into recoverable errors in Rust and learn how to use the Result type to handle errors in a safe and efficient way.
We’ll cover:
– What are recoverable errors in Rust and how they differ from unrecoverable errors
– The Result type and how it is used to handle recoverable errors
– How to use the match expression to handle different types of errors
– The ? operator and how it can simplify error handling code.
By the end of this video, you’ll have a solid understanding of recoverable errors in Rust and be equipped with the knowledge to handle them in your own Rust programs.
Code and slide deck : https://github.com/timurguvenkaya/near-sc-security-course
Section Overview: In this section, the instructor introduces error handling in Rust and explains the differences between recoverable and unrecoverable errors.
Section Overview: In this section, the instructor provides an example of how to handle a recoverable error using Rust’s match
keyword.
match
keyword to match on both error and success cases when handling a recoverable error.Section Overview: In this section, the instructor provides additional examples of how to handle errors using Rust’s match
keyword and question mark operator.
match
keyword with result type when opening a file.Section Overview: In this section, the instructor concludes the video by summarizing the key points covered in this section.
match
keyword or question mark operator.0 of 2 Questions completed
Questions:
You have already completed the assignment before. Hence you can not start it again.
Assignment is loading…
You must sign in or sign up to start the assignment.
You must first complete the following:
0 of 2 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Question 1: Which of the following best describes a recoverable error in Rust?
Question 2: True or False – Recoverable errors in Rust use the Result type with data inside the Ok variant and an error inside the Err variant.
Connect Your Wallet
What is a Wallet?
Safely store and transfer your crypto and NFTs.
No need to create new accounts or credentials. Connect your wallet and you are good to go!