避免捕获异常的更快方法
Faster way to avoid catching an exception
有没有办法暂时停止捕获某些异常?
关键是当你有更多的异常被捕获在代码中并且你想评论它们因为你想看到异常发生时打印的所有东西(打印异常是不够的),你有注释 try, except, code in except, finally, code in finally 并更改可以引发异常的代码的缩进。当你必须多次这样做时,这个注释非常耗时。
#try:
pel.check_one_destination()
#except Exception as e:
#pel.driver.save_screenshot('log.png')
#print e
您可以在 except 块中添加 raise
关键字,它会引发捕获的异常。在测试期间发现它很有用。
例子-
try:
#code that leads to exception
except Exception as e:
#handle exception
raise #for testing what the exception was, and etc.
有没有办法暂时停止捕获某些异常?
关键是当你有更多的异常被捕获在代码中并且你想评论它们因为你想看到异常发生时打印的所有东西(打印异常是不够的),你有注释 try, except, code in except, finally, code in finally 并更改可以引发异常的代码的缩进。当你必须多次这样做时,这个注释非常耗时。
#try:
pel.check_one_destination()
#except Exception as e:
#pel.driver.save_screenshot('log.png')
#print e
您可以在 except 块中添加 raise
关键字,它会引发捕获的异常。在测试期间发现它很有用。
例子-
try:
#code that leads to exception
except Exception as e:
#handle exception
raise #for testing what the exception was, and etc.