CJCoding With Joseph

Identify The Exception Type

Read an integer n. If n == 0, throw a DivideByZeroException; if n < 0, throw an ArgumentException; otherwise print Value: <n>. Use a single catch (Exception ex) that catches any of them and prints Caught: <ex.GetType().Name>. Use top-level statements.

Input 5 prints: Value: 5
Input 0 prints: Caught: DivideByZeroException
Input -1 prints: Caught: ArgumentException

Expected Output:

Value: 5
Topics:
Exceptions
๐Ÿ“ฅ Auto-Input:
5\n
This input is automatically fed to your program's stdin
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.