class MyException(Exception):
def __init__(self, string, num):
Exception.__init__(self, string, num)
self.string = string
self.num = num
self.reason = "reason"
def __str__(self):
return "SelfDefinedError : [%s] : %s %s" %(self.reason, str(self.string), str(self.num))
class test:
def __init__(self, string, num):
if isinstance(string, str) and isinstance(num, int):
self.string = string
self.num = num
else:
raise MyException, (string, num)
t = test('test1', '2')
python exception
最新推荐文章于 2023-04-05 20:00:00 发布