finally会被执行到

1.catch中 throw

       try{
           int i = 1/0;
       }catch (Exception e) {
           throw e;

       }finally {
           System.out.println("finally");
       }    

【java】try,catch,finally 各种情况是否被执行到

 

 

2.catch中return

    try{
           int i = 1/0;
       }catch (Exception e) {
           return;

       }finally {
           System.out.println("finally");
       }

 

 

 

 

 

finally不会被执行到

1.catch中退出程序

    try{
           int i = 1/0;
       }catch (Exception e) {
           System.exit(1);

       }finally {
           System.out.println("finally");
       }

 

相关文章:

  • 2021-09-02
  • 2021-12-27
  • 2022-12-23
  • 2021-11-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
相关资源
相似解决方案