无论是在try还是在except中,遇到return时,只要设定了finally语句,就会中断当前的return语句,跳转到finally中执行,如果finally中遇到return语句,就直接返回,不再跳转回try/excpet中被中断的return语句
捕获异常后再次抛出异常:
捕获后再抛出,会被调用他的上一级再次捕获
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 def a(): 2 try: 3 int('N') 4 except ValueError: 5 print('a-error') 6 raise ValueError 7 8 9 def b(): 10 try: 11 a() 12 print('b-try') 13 except ValueError: 14 print('b-error') 15 16 17 if __name__ == '__main__': 18 b() 19 20 # a-error 21 # b-error
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 def a(): 2 try: 3 int('N') 4 except ValueError: 5 print('a-error') 6 raise ValueError 7 except Exception: 8 print('a-all-error') 9 10 11 def b(): 12 try: 13 a() 14 print('b-try') 15 except ValueError: 16 print('b-error') 17 18 19 if __name__ == '__main__': 20 b() 21 22 # a-error 23 # b-error