← 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= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
FunctionsExceptions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.