Multiple Catch Blocks
mediumQuestion 151Write two functions that demonstrate catching different exception types:
1. processInput(int value): throws a std::invalid_argument with "Negative input" if value < 0; throws a std::out_of_range with "Value too large" if value > 1000; otherwise prints "Processing: " followed by value.
2. safeProcess(int value): calls processInput(value) inside a try block with two separate catch blocks:
- Catch invalid_argument: print "Invalid: " followed by e.what()
- Catch out_of_range: print "Range error: " followed by e.what()
Do NOT write a main function.
Expected output
Processing: 50= newline. The output ends with a newline, so 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.