Answers for "custom error handling python"

2

python custom errors

class MyException(Exception):
  """You can put code here"""
  pass

class MyOtherException(MyException):
  """You can also put code here"""
  pass
Posted by: Guest on June-29-2021
2

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
Posted by: Guest on April-19-2021

Python Answers by Framework

Browse Popular Code Answers by Language