How do you raise an exception and create a custom one?

Python errors and files · Freshers

Model answer

raise ValueError("Invalid age"). For a custom one, subclass Exception: class InsufficientFunds(Exception): pass. Custom exceptions make errors meaningful and easy to catch separately.

Learn this topic

Handling Errors in Python: try, except, finally and raise in the course Python for Beginners: Learn to Code with Real Projects.

Sign in to add your own answer.

More questions