Answers for "python raising custom exception"

0

raising custom exception python

class UnderAge(Exception):
   pass
 
def verify_age(age):
   if int(age) < 18:
       raise UnderAge("You must be at least 18 years old")
   else:
       print('Age: '+str(age))
 
# main program
verify_age(23)  # won't raise exception
verify_age(17)  # will raise exception
Posted by: Guest on May-25-2021

Code answers related to "python raising custom exception"

Python Answers by Framework

Browse Popular Code Answers by Language