Python异常处理

Python异常处理

批文件处理,监视运行成功率。

sum = 0

for i in imgs_group:
    try:
       # codes
    except Exception as e:
        print(e)
        sum += 1

print(sum)

扩展

s1 = 'hello'
try:
    int(s1)
except IndexError as e:
    print(e)
except KeyError as e:
    print(e)
except ValueError as e:
    print(e)
except Exception as e:
    print(e)
else:
    print('try内代码块没有异常则执行我')
finally:
    print('无论异常与否,都会执行该模块,通常是进行清理工作')

posted @ 2022-07-20 20:23  CuriosityWang  阅读(26)  评论(0编辑  收藏  举报