When an exception is defined by the user based on the problem requirements is known as
customized or user-defined exception. Sometimes we need to define customized
exception to fulfill the program requirements. Here the user-defined exception has to be
derived from Exception class directly or indirectly.
Here we have created two custom exceptions like TooOldException and
TooYoungException which are derived from Exception class. Like other exceptions, these
new exception can be raised using raise statement.
age=int(input("enter the age value"))
raise TooOldException("Sorry!We can't help u")
raise TooYoungException("Sorry!U have to wait some years")
print("Welcome, asap we will provide best matched profile")
Here I have presented a logic for matrimonial application. If somebody will enter the age
value greater than 60 then the application will throw an exception that is TooOldException,
and if the age value is less than 18, then the application will throw an exception that is
TooYoungException, otherwise application will give a positive response.