Try{...}catch{...}finally{...}于return

发表于:2007-07-04来源:作者:点击数: 标签:
(1)finally{}中return
eg.
try{
       
         
      }
catch(Exception e){}
        finally{return;}
        int I=5;
错误:不能到达int I=5

(2)try{}中return;
try{
        System.out.println("try");
        return;
        }catch(Exception e){System.out.println("catch");}
        finally{
              System.out.println("finally");
              }
System.out.println("last");
结果try,finally输出,在try 中finally是必执行的.
try->finally{}->stop

(3)在catch{}中return;
try{}->抛出异常->catch{}->finally{}->stop

(4)用system.exit(0),全部退出,不执行任何步骤。

原文转自:http://www.ltesting.net