w3resource

Rust Handling Errors with Result and Option Exercises

Rust Handling Errors with Result and Option Exercises [8 exercises with solution and Explanation]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a Rust program that reads an integer from user input and prints its cube root, handling invalid input.

Click me to see the solution

2. Write a Rust function that reads a file and prints its contents, handling file not found and permission errors.

Click me to see the solution

3. Write a Rust function that reads a CSV file, parses it into structured data, and handles parsing errors.

Click me to see the solution

4. Write a Rust program that asks the user for a filename, reads the file, and counts the number of lines, handling I/O errors.

Click me to see the solution

5. Write a Rust function that divides two numbers and prints the result or an error message if division by zero occurs.

Click me to see the solution

6. Write a Rust program that accepts user input for a date, parses it, and prints it in a different format, handling parsing errors.

Click me to see the solution

7. Write a Rust program that reads a JSON file, parses it, and prints specific data fields, handling parsing and I/O errors.

Click me to see the solution

8. Write a Rust function that performs network requests, returning data or an error if the request fails.

Click me to see the solution

Rust Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/rust/error_handling/handling-errors-with-result-and-option.php