Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: python sleep 
Python :: random.uniform python 
Python :: epoch to gmt python 
Python :: django-mathfilters 
Python :: to_cvs python 
Python :: python elapsed time in milliseconds 
Python :: change password django 
Python :: add list to end of list python 
Python :: how to access the last element of a list in python 
Python :: text animation python 
Python :: pyton count number of character in a word 
Python :: line plotly with shaded area 
Python :: python list of dictionaries 
Python :: python replace n with actual new line 
Python :: how to plot in python 
Python :: remove  python 
Python :: install fastapi 
Python :: convex hull python 
Python :: lambda and function in python 
Python :: pandas write csv 
Python :: how to take a column from dataset in python 
Python :: pycord discord discordpy get total slash commands and total commands regestered in your bot 
Python :: if a list has a string remove 
Python :: how to count repeated words in python 
Python :: highlight null/nan values in pandas table 
Python :: how to make software in python 
Python :: Python Datetime Get year, month, hour, minute, and timestamp 
Python :: python threading return value 
Python :: generate random list and find max in list python 
Python :: python how to check in a list 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =