def some_function(){
try:
#logic to load the page. If it is successful, it will not go to except.
return True
except:
#will come to this clause when page will throw error.
return False
}
while(True)
if some_function():
break
else:
time.sleep(2)
continue
试试这样的:
为什么不这样做:
try块中的所有内容都将被执行,直到引发一个
Exception
,这种情况下将调用except
块。所以你在第一次迭代中就崩溃了。
我想你的意思是:
当引发异常时,while循环将被中断。
相关问题 更多 >
编程相关推荐