try{
System.out.println("ok");
}finally{
System.out.println("error");
}try没有catch的情况;
这段代码可以编译并运行;以前没遇到过,很惊奇,为什么能这样?既然能这样,为什么不能只有一个try(试了,只有一个try编译报错)
System.out.println("ok");
}finally{
System.out.println("error");
}try没有catch的情况;
这段代码可以编译并运行;以前没遇到过,很惊奇,为什么能这样?既然能这样,为什么不能只有一个try(试了,只有一个try编译报错)
解决方案 »
- 求正则表达式
- Dom4j修改xml文件
- java生成xml报错!!!急急急!!求各位帮忙!
- 用Java代码编写
- 请教邮件服务器能发邮件不能收邮件!
- 这个问题我思考了好久,但是都没结果!
- 我想从Oracle官网下载JSF的jar包,不知道该下载哪个
- 开发时什么时候确定前端页面?
- 问个弱智问题:java的web service容器有哪些?
- 请问如何去掉:"EjbBook.ejbgrpx": Spaces in the classpath may cause WebLogic EJBC utility to produce fatal compile errors.
- win7 运行socket程序报错
- Spring 从properties 文件注入 List 问题
如果只添加一个try的话,那么要try语句就没有什么用了。
private void tex(){
File file = null;
file.delete();
}
public static void main(String[] args){
ETest et = new ETest();
try{
et.tex();
}finally{
System.out.println("finally");
}
}
}执行结果:finally
Exception in thread "main" java.lang.NullPointerException
at com.lkl.test.exceptiontest.ETest.tex(ETest.java:8)
at com.lkl.test.exceptiontest.ETest.main(ETest.java:14)
和
System.out.println("ok");
System.out.println("error");
这样写效果是一样的。