有没有一种方法可以暂时停止捕获某些异常?
关键是,当您在代码中捕获到更多异常并要注释它们时,因为您想查看引发异常时所打印的所有内容(打印异常不足),则必须对try进行注释,但,代码中的代码(最终代码除外)以及更改代码的缩进以引发异常。当您必须进行多次评论时,此评论非常耗时。
#try:
pel.check_one_destination()
#except Exception as e:
#pel.driver.save_screenshot('log.png')
#print e
您可以只raise
在except块内添加关键字,这将引发捕获到的异常。发现它在测试过程中很有用。
例子 -
try:
#code that leads to exception
except Exception as e:
#handle exception
raise #for testing what the exception was, and etc.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句