โ Back to Exceptions
Question 691
Custom Exception With Data and finally
Custom Exception With Data and finally
Define anInsufficientFundsExceptionwith anint Shortfallproperty set through its constructor. The balance is100. Read anamountto withdraw; ifamount > balance, throw the exception carrying the shortfall (amount - balance). Otherwise printWithdrew <amount>. Catch it and printShort by <shortfall>. Afinallyblock always printsTransaction complete. Use top-level statements, then declare the class after them. Input50prints: Withdrew 50 Transaction complete Input150prints: Short by 50 Transaction complete
Expected Output:
Withdrew 50 Transaction complete
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.