creating custom exception class you can create custom exception class by extending baseexception class or subclass of baseexception from above diagram we can see most of the exception classes in python extends from the baseexception class you can derive your own exception class from baseexception class or from its subclass create new file called negativenumberexception py and write the following code class negativenumberexception(runtimeerror)def __init__(selfage)super(__init__(self age age above code creates new exception class named negativenumberexceptionwhich consists of only constructor which call parent class constructor using super()__init__(and sets the age