说我有这个代码:
def wait_for_x(timeout_at=None):
while condition_that_could_raise_exceptions
if timeout_at is not None and time.time() > timeout_at:
raise SOMEEXCEPTIONHERE
do_some_stuff()
try:
foo()
wait_for_x(timeout_at=time.time() + 10)
bar()
except SOMEEXCEPTIONHERE:
# report timeout, move on to something else
如何SOMEEXCEPTIONHERE
为函数选择异常类型?为该函数创建一个唯一的异常类型是否合理,这样就不会有condition_that_could_raise_exceptions
引发相同异常类型的危险?
wait_for_x.Timeout = type('Timeout', (Exception,), {})