推荐 最新
爱打瞌睡的三角龙

python函数调用触发except后,如何立即中断当前循环,进入下一个循环?

一小段python代码: for item in [n1,n2,n3]: f1(args1) f2(args2) f3(args3) 三个函数的结构类似 def f1(args): try: doing something except: pass 我的需求:f1 ,f2,f3这三个函数,无论哪个函数在运行中触发了except,那么当前循环立即中断,进入下一个循环。 请问,如何达到这个需求?

0
1
0
浏览量17
六股小子

try except结构调用函数的输出结果为何是这样?

定义一个简单的异常类: "class myException(Exception): pass" 定义一个函数 def f1(): try: print(1/0) except: raise myException('my exception') 运行f1() Traceback (most recent call last): File "", line 3, in f1 ZeroDivisionError: division by zero During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "", line 5, in f1 __main__.myException: my exception 写一段代码调用f1(): try: f1() except myException as e: print(e) 为何输出结果仅仅有 my exception 下面这些信息为何不出现? Traceback (most recent call last): File "", line 3, in f1 ZeroDivisionError: division by zero During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "", line 5, in f1 __main__.myException: my exception

0
1
0
浏览量12