RSS
热门关键字:  Java  idc 下载  域名  idc  idc+下载
当前位置 :| 主页>程序设计>JAVA编程>

try catch finally与return的执行顺序

来源:商务互联 作者:罗代均 时间:2008-03-31 点击:
import java.io.*;
public class Mine{
  public static void main(String argv[]){
  Mine m=new Mine();
    System.out.println(m.amethod());
  }
public int amethod(){
       try{
           FileInputStream dis =new FileInputStream("Hello.txt"); //1,抛出异常
       }catch ( Exception ex) {
               System.out.println("No such file found");   //2.catch捕获异常,并执行
               return -1;                                  //4,return 返回
       }finally{
               System.out.println("Doing finally");  //3.finally一定会执行,在return之前。
       }
        return 0;
    }
}

运行结果:

C:\java>java   Mine
No such file found
Doing finally
-1
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
栏目列表