โ Back to Functions
Question 151
Multiple Catch Blocks
Multiple Catch Blocks
Write two functions that demonstrate catching different exception types: 1.processInput(int value): throws astd::invalid_argumentwith"Negative input"ifvalue < 0; throws astd::out_of_rangewith"Value too large"ifvalue > 1000; otherwise prints"Processing: "followed by value. 2.safeProcess(int value): callsprocessInput(value)inside atryblock with two separate catch blocks: - Catchinvalid_argument: print"Invalid: "followed bye.what()- Catchout_of_range: print"Range error: "followed bye.what()Do NOT write a main function.
Expected Output:
Processing: 50
Topics:
FunctionsExceptions
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.