CJCoding With Joseph

Custom Exception Class

Define 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
Topics:
Exceptions
๐Ÿ“ฅ Auto-Input:
100\n40\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 (cw, cr, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.