← All practice pages
Python
Python Exception Handling
Exceptions are how Python reports that something went wrong. try/except lets you catch the failure and decide what happens next instead of crashing.
Try it now
Define a custom exception "InsufficientFundsError" that subclasses Exception, and raise it from a withdraw function when the requested amount exceeds the balance.
Create a free account to run your answer and get ARIA's review.