Custom Exception Class
mediumQuestion 740Define a custom exception InsufficientFundsException that inherits from Exception and takes a message. Read a balance and a withdrawal amount. If the amount is greater than the balance, throw the custom exception with message Insufficient funds; otherwise print New balance: <balance - amount>. Catch it and print ex.Message. Declare the class after the top-level statements.
Input 100 then 40 prints: New balance: 60
Input 100 then 150 prints: Insufficient funds
Expected output
New balance: 60= 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.