โ Back to Exceptions
Question 688
Throw From a Method
Throw From a Method
Read an integernand printResult: <100 / n>using a helper methodDivideHundred(int x)that returns100 / xbut throwsnew DivideByZeroException()whenxis0. Catch the exception in the top-level code and print exactlyCannot divide by zero. Use top-level statements withtry/catch, and declare the helper method after the statements. Input4prints: Result: 25 Input0prints: Cannot divide by zero
Expected Output:
Result: 25
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.