Python·100 questions

How to create a custom exception?

Answer
Inherit from Exception: class MyError(Exception): pass.
Use a meaningful name.
Pass a message: raise MyError('...').
For parameters — store them in attributes.
Do not inherit from BaseException.
Was this answer helpful?

More questions in this topic

Related questions from other topics