江西广告网

标题: Java异常时,finally [打印本页]

作者: 早妖的夏天    时间: 2009-1-23 11:48
标题: Java异常时,finally
package lee; import java.io.*; public class Test1{ public static void main(String argv[]){ Test1 m=new Test1(); 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; } } 输出结果为: No such file found Doing finally -1




欢迎光临 江西广告网 (http://bbs.jxadw.com/) Powered by Discuz! X3.2