CJCoding With Joseph
15per day

Checked Exception and throws

Create a checked exception and use it:
1. Define InsufficientFundsException that extends Exception with a constructor that accepts a message string.
2. Write withdraw(double balance, double amount) throws InsufficientFundsException — throw the exception with message "Not enough funds" if amount > balance.
3. In main, read balance and amount. Call withdraw, print "Withdrawal successful" or "Error: " + e.getMessage() if caught.

Because InsufficientFundsException extends Exception (not RuntimeException), withdraw must declare throws.

⚠️ AUTO-INPUT MODE: The input stream will automatically contain '50.0 100.0\n'.

Expected Output:

Error: Not enough funds
Topics:
Miscellaneous
📥 Auto-Input:
50.0 100.0\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 (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.