python自定义异常类
作者:互联网
#自定义异常类
class AgeError(Exception):
def __init__(self,errorInfo):
Exception.__init__(self)
self.errorInfo =errorInfo
def __str__(self):
return str(self.errorInfo)+'年龄错误!!'
age = int(input('输入一个年龄:'))
if age < 1 or age > 150:
raise AgeError(age)
else:
print('正常的年龄', age)
python 自定义异常类的用法
标签:__,自定义,python,AgeError,self,errorInfo,异常,age 来源: https://blog.csdn.net/yongwuhen/article/details/122685154