Practice 50 Error Propagation Coding Questions, TechnoVlogs

Practice 50 Error Propagation Coding Questions


Q1. Write a Rust program that propagates an error from a function that divides two numbers.  
Input:  
Numerator: 10, Denominator: 0  
Expected Output: 
Error: Cannot divide by zero

Q2. Write a Rust program that propagates an error when trying to open a file that does not exist.  
Input:  
File path: "invalid_file.txt"  
Expected Output: 
Error: Could not open the file

Q3. Write a Rust program to propagate an error from a function that parses a string to an integer.  
Input:  
String: "abc"  
Expected Output: 
Error: Failed to parse integer

Q4. Write a Rust program to propagate an error from a function that reads a number from user input.  
Input:  
User input: "not_a_number"  
Expected Output: 
Error: Invalid input

Q5. Write a Rust program that propagates an error if a network connection fails.  
Input:  
Connection status: "failed"  
Expected Output: 
Error: Connection failed

Q6. Write a Rust program to propagate an error when a file read operation fails.  
Input:  
File path: "non_existent_file.txt"  
Expected Output: 
Error: Could not read the file

Q7. Write a Rust program that propagates an error when converting a value to a type that is incompatible.  
Input:  
Value: "hello" (to convert to an integer)  
Expected Output: 
Error: Conversion failed

Q8. Write a Rust program that propagates an error when accessing an invalid array index.  
Input:  
Array: [1, 2, 3], Index: 5  
Expected Output: 
Error: Index out of bounds

Q9. Write a Rust program to propagate an error if a user tries to divide by zero.  
Input:  
Numerator: 25, Denominator: 0  
Expected Output: 
Error: Division by zero

Q10. Write a Rust program to propagate an error if a file cannot be found.  
Input:  
File path: "missing_file.txt"  
Expected Output: 
Error: File not found

Q11. Write a Rust program that propagates an error when a number exceeds a specified limit.  
Input:  
Number: 150, Limit: 100  
Expected Output: 
Error: Number exceeds limit

Q12. Write a Rust program that propagates an error when a value is not in the expected range.  
Input:  
Value: 200, Range: 1 to 100  
Expected Output: 
Error: Value out of range

Q13. Write a Rust program that propagates an error when a required environment variable is missing.  
Input:  
Environment variable: "MY_VAR"  
Expected Output: 
Error: Environment variable not set

Q14. Write a Rust program to propagate an error when reading from an empty file.  
Input:  
File path: "empty_file.txt"  
Expected Output: 
Error: File is empty

Q15. Write a Rust program that propagates an error when a required API call fails.  
Input:  
API Response: "Failed"  
Expected Output: 
Error: API call failed

Q16. Write a Rust program to propagate an error when trying to parse an invalid date format.  
Input:  
Date string: "13-32-2025"  
Expected Output: 
Error: Invalid date format

Q17. Write a Rust program to propagate an error when a function receives invalid parameters.  
Input:  
Parameter: -1  
Expected Output: 
Error: Invalid parameter

Q18. Write a Rust program that propagates an error when attempting to access an unavailable network resource.  
Input:  
Resource: "network_resource"  
Expected Output: 
Error: Resource not found

Q19. Write a Rust program to propagate an error when an invalid file extension is detected.  
Input:  
File name: "document.txt" (should be .pdf)  
Expected Output: 
Error: Invalid file extension

Q20. Write a Rust program to propagate an error when a user enters an invalid menu choice.  
Input:  
User input: "invalid_option"  
Expected Output: 
Error: Invalid menu choice

Q21. Write a Rust program to propagate an error when performing an arithmetic operation with a negative number.  
Input:  
Number: -5, Operation: square root  
Expected Output: 
Error: Cannot compute square root of negative number

Q22. Write a Rust program to propagate an error when the disk is full during a file write operation.  
Input:  
Disk space: 0 bytes  
Expected Output: 
Error: Disk is full

Q23. Write a Rust program that propagates an error when an invalid password is entered.  
Input:  
Password: "incorrect"  
Expected Output: 
Error: Invalid password

Q24. Write a Rust program to propagate an error when a required configuration file is missing.  
Input:  
File path: "config.json"  
Expected Output: 
Error: Configuration file not found

Q25. Write a Rust program to propagate an error when accessing a deleted file.  
Input:  
File path: "deleted_file.txt"  
Expected Output: 
Error: File has been deleted

Q26. Write a Rust program to propagate an error when a network connection times out.  
Input:  
Connection status: "timed_out"  
Expected Output: 
Error: Network connection timed out

Q27. Write a Rust program to propagate an error when trying to parse an unsupported data format.  
Input:  
Data format: "csv" (expected: "json")  
Expected Output: 
Error: Unsupported data format

Q28. Write a Rust program to propagate an error when trying to perform a file read operation that exceeds buffer size.  
Input:  
File size: 200 MB, Buffer size: 100 MB  
Expected Output: 
Error: Buffer overflow

Q29. Write a Rust program that propagates an error when trying to access a resource without proper authentication.  
Input:  
Authentication status: "failed"  
Expected Output: 
Error: Authentication failed

Q30. Write a Rust program that propagates an error when trying to access a database that is not reachable.  
Input:  
Database status: "not reachable"  
Expected Output: 
Error: Database connection failed

Q31. Write a Rust program that propagates an error when an invalid user ID is provided.  
Input:  
User ID: -5  
Expected Output: 
Error: Invalid user ID

Q32. Write a Rust program to propagate an error when an API returns a response with an unsupported status code.  
Input:  
API status code: 500  
Expected Output: 
Error: Unsupported status code

Q33. Write a Rust program to propagate an error when trying to access a property of a `None` value in an `Option`.  
Input:  
Option: None  
Expected Output: 
Error: Value is None

Q34. Write a Rust program to propagate an error when an integer overflow occurs.  
Input:  
Integer: 2147483647 + 1  
Expected Output: 
Error: Integer overflow

Q35. Write a Rust program that propagates an error when trying to open a read-only file for writing.  
Input:  
File path: "readonly_file.txt"  
Expected Output: 
Error: Cannot write to read-only file

Q36. Write a Rust program that propagates an error when a required field in a form is missing.  
Input:  
Form field: "email"  
Expected Output: 
Error: Missing email field

Q37. Write a Rust program to propagate an error when a required key is missing in a map.  
Input:  
Key: "username"  
Expected Output: 
Error: Missing key: username

Q38. Write a Rust program that propagates an error when trying to write data to a full disk.  
Input:  
Disk status: "full"  
Expected Output: 
Error: Cannot write data to full disk

Q39. Write a Rust program to propagate an error when a user tries to access an unauthorized page.  
Input:  
Page: "/admin"  
Expected Output: 
Error: Unauthorized access

Q40. Write a Rust program that propagates an error when an integer is not positive.  
Input:  
Integer: -1  
Expected Output: 
Error: Integer must be positive

Q41. Write a Rust program that propagates an error when trying to perform a task without sufficient privileges.  
Input:  
Privileges: "guest"  
Expected Output: 
Error: Insufficient privileges

Q42. Write a Rust program that propagates an error when the user inputs a value out of range.  
Input:  
Input value: 101, Range: 1 to 100  
Expected Output: 
Error: Value out of range

Q43. Write a Rust program that propagates an error when an expected service is unavailable.  
Input:  
Service: "weather_service"  
Expected Output: 
Error: Service unavailable

Q44. Write a Rust program to propagate an error when trying to retrieve an invalid API key.  
Input:  
API key: "invalid_key"  
Expected Output: 
Error: Invalid API key

Q45. Write a Rust program that propagates an error when accessing a resource that has been deprecated.  
Input:  
Resource: "old_api"  
Expected Output: 
Error: Resource is deprecated

Q46. Write a Rust program to propagate an error when a required parameter is missing in a function call.  
Input:  
Parameter: None  
Expected Output: 
Error: Missing required parameter

Q47. Write a Rust program that propagates an error when a given URL is malformed.  
Input:  
URL: "htp://invalid-url"  
Expected Output: 
Error: Malformed URL

Q48. Write a Rust program that propagates an error when performing an unsupported operation.  
Input:  
Operation: "undefined_op"  
Expected Output: 
Error: Unsupported operation

Q49. Write a Rust program to propagate an error when trying to access a file that is locked by another process.  
Input:  
File: "locked_file.txt"  
Expected Output: 
Error: File is locked by another process

Q50. Write a Rust program that propagates an error when a required resource is missing during initialization.  
Input:  
Resource: "database"  
Expected Output: 
Error: Missing initialization resource

Share on Social Media