【发布时间】:2019-04-08 10:36:19
【问题描述】:
当我运行这段代码时:
i=0
while i<5:
i=i+1;
try:
SellSta=client.get_order(symbol=Symb,orderId=SellOrderNum,recvWindow=Delay)
except client.get_order as e:
print ("This is an error message!{}".format(i))
#End while
我收到了这个错误:
TypeError: catching classes that do not inherit from BaseException is not allowed
我读过这个胎面Exception TypeError warning sometimes shown, sometimes not when using throw method of generator,这个Can't catch mocked exception because it doesn't inherit BaseException也读过这个https://medium.com/python-pandemonium/a-very-picky-except-in-python-d9b994bdf7f0
我用这段代码修复它:
i=0
while i<5:
i=i+1;
try:
SellSta=client.get_order(symbol=Symb,orderId=SellOrderNum,recvWindow=Delay)
except:
print ("This is an error message!{}".format(i))
#End while
结果是忽略错误并转到下一个,但我想捕获错误并打印它。
【问题讨论】:
-
由于这个问题在我的搜索中出现的频率很高 - 在我的情况下,错误是由我的简单错误引起的,实例化错误类,即
except TypeError():而不是except TypeError:。
标签: python exception typeerror binance