class Exceptions:
class A(Exception):
pass
class B(Exception):
pass
i=0
while i<30:
try:
if i%5==0:
raise Exceptions.A
if i%3==0:
raise Exceptions.B
print(1,i)
except Exceptions.A:
print(2,i)
except Exceptions.B:
print(3,i)
continue
finally:
i += 1
运行结果:
2 0
1 1
1 2
3 3
1 4
2 5
3 6
1 7
1 8
3 9
2 10
1 11
3 12
1 13
1 14
2 15
1 16
1 17
3 18
1 19
2 20
3 21
1 22
1 23
3 24
2 25
1 26
3 27
1 28
1 29