因为需要花式catch exception
class MyException(Exception):
def __init__(self, arg1, arg2):
super(MyException, self).__init__(arg1, arg2)
self.arg1 = arg1
self.arg2 = arg2
class MyException(Exception):
def __init__(self, message, level='info'):
super(MyException, self).__init__(message, level)
self.message = message
self.level = level
if __name__ == '__main__':
try:
raise PortNotFoundPidError('fuck u', level='emergent')
except PortNotFoundPidError as e:
print(e)
print('Error message:{} \nError level:{}'.format(e.message, e.level))
/usr/local/bin/python2.7 /Users/psyduck/GitLab/monitor/scripts/Errors.py
##### output #####
# ('fuck u', 'emergent')
# Error message:fuck u
# Error level:emergent
为什么要super(MyException, self).__init__()
?
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。