โ Back to Exceptions
Question 649
Multiple Catch Blocks
Multiple Catch Blocks
Read two integers and print their quotient. Use two separate catch blocks: aFormatExceptionprintsNot a valid number, and aDivideByZeroExceptionprintsCannot divide by zero. The order matters: the more specific type is matched first. Use top-level statements. Input10then2prints: 5 Input10then0prints: Cannot divide by zero Inputxthen2prints: Not a valid number
Expected Output:
5
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.