← Back to Miscellaneous
Question 219
Checked Exception and throws
Checked Exception and throws
Create a checked exception and use it: 1. DefineInsufficientFundsExceptionthat extendsExceptionwith a constructor that accepts a message string. 2. Writewithdraw(double balance, double amount) throws InsufficientFundsException— throw the exception with message"Not enough funds"ifamount > balance. 3. Inmain, read balance and amount. Callwithdraw, print"Withdrawal successful"or"Error: " + e.getMessage()if caught. BecauseInsufficientFundsExceptionextendsException(notRuntimeException),withdrawmust declarethrows. ⚠️ AUTO-INPUT MODE: The input stream will automatically contain'50.0 100.0\n'.
Expected Output:
Error: Not enough funds
Topics:
Miscellaneous
Code Editor
1
Tab to indent · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.