Wrap With Inner Exception
hardQuestion 754Use a nested try/catch. Inner try: read n; if n < 0, throw new ArgumentException("negative value"); otherwise print Value: <n>. The inner catch wraps it: throw new InvalidOperationException("validation failed", ex), passing the original as the inner exception. The outer catch prints ex.Message, then prints Caused by: <ex.InnerException.Message>. Use top-level statements.
Input 5 prints: Value: 5
Input -2 prints:
validation failed
Caused by: negative value
Expected output
Value: 5= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Exceptions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.