Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python custom exception

class UnderAge(Exception):
   pass
 
def verify_age(age):
   if int(age) < 18:
       raise UnderAge
   else:
       print('Age: '+str(age))
 
# main program
verify_age(23)  # won't raise exception
verify_age(17)  # will raise exception
Source by www.journaldev.com #
 
PREVIOUS NEXT
Tagged: #python #custom #exception
ADD COMMENT
Topic
Name
8+4 =