CJCoding With Joseph

Two Catch Blocks

Read two integers and print a / b. Handle two different failures with two catch blocks: a FormatException (bad number) prints Invalid number, and a DivideByZeroException prints Cannot divide by zero. Use top-level statements with try/catch.

Input 20 then 4 prints: 5
Input 20 then 0 prints: Cannot divide by zero
Input x then 4 prints: Invalid number

Expected Output:

5
Topics:
Exceptions
๐Ÿ“ฅ Auto-Input:
20\n4\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.