class TimeOutError(RuntimeError):
def __init__(self, *args, **kwargs):
super(TimeOutError, self).__init__(*args, **kwargs)
class TestNameError(NameError):
def __init__(self, *args, **kwargs):
super(TestNameError, self).__init__(*args, **kwargs)
def test():
resp = 'u'
if not resp:
info = '测试名称错误'
raise TestNameError('[Error]:{}'.format(info))
time = 5
if time > 3:
info = '测试超时错误'
raise TimeOutError('[Error]:{}'.format(info))
if __name__ == '__main__':
try:
test()
except TimeOutError as t:
print(t)
except TestNameError as e:
print(e)