📜  python自定义异常 - Python代码示例

📅  最后修改于: 2022-03-11 14:47:25.292000             🧑  作者: Mango

代码示例2
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