โ Back to Exceptions
Question 684
Filter With a when Clause
Filter With a when Clause
Read an integercode, thenthrow new InvalidOperationException(code.ToString()). Using an exception filter (catch ... when (...)), printNot Foundonly when the exception message is404; otherwise a secondcatchprintsOther error. Use top-level statements withtry/catch. Input404prints: Not Found Input500prints: Other error
Expected Output:
Not Found
Topics:
Exceptions
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.