CJCoding With Joseph

Multiple Catch Blocks

Write 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
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.