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.
2. Write a Rust function that reads a file and prints its contents, handling file not found and permission errors.
3. Write a Rust function that reads a CSV file, parses it into structured data, and handles parsing errors.
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.
5. Write a Rust function that divides two numbers and prints the result or an error message if division by zero occurs.
6. Write a Rust program that accepts user input for a date, parses it, and prints it in a different format, handling parsing errors.
7. Write a Rust program that reads a JSON file, parses it, and prints specific data fields, handling parsing and I/O errors.
8. Write a Rust function that performs network requests, returning data or an error if the request fails.
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.
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://w3resource.com/rust/error_handling/handling-errors-with-result-and-option.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics