Function That Throws
hardQuestion 756Read two integers and print Result: <Divide(a, b)>. Write a local function int Divide(int x, int y) that throws new DivideByZeroException("cannot divide by zero") when y is 0, and otherwise returns x / y. Catch that exception in the caller and print its message. Use top-level statements (declare the local function at the end).
Input 10 then 2 prints: Result: 5
Input 10 then 0 prints: cannot divide by zero
Expected output
Result: 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.