โ Back to Exceptions
Question 650
Custom Exception Class
Custom Exception Class
Define a custom exceptionInsufficientFundsExceptionthat inherits fromExceptionand takes a message. Read a balance and a withdrawal amount. If the amount is greater than the balance, throw the custom exception with messageInsufficient funds; otherwise printNew balance: <balance - amount>. Catch it and printex.Message. Declare the class after the top-level statements. Input100then40prints: New balance: 60 Input100then150prints: Insufficient funds
Expected Output:
New balance: 60
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.