public class test2 {
static void fun(){
try{
throw new NullPointerException();
}catch(Exception e){
System.out.println("第一个try块!");
}finally{
System.out.println("第一个finally!");
}
}
public static void main(String[] argv){
try{
fun();
}catch(Exception e){
System.out.println("第二个try块!");
}finally{
System.out.println("第二个finally!");
}
}
}
运行结果为:
第一个try块!
第一个finally!
第二个finally!
为什么主方法里的catch不执行啊?
!
解决方案 »
- 按照要求,求设计验证 IP 的思路
- 为什么可以用FileReader正确读取FileOutputStream写入文件的数据呢?
- TableModle中的数据居中????
- netbeans如何加载图片?
- java中有没有在文件中删除或者修改一行或者几个字符的函数?怎么实现?
- 给分
- 线程问题????????????
- JLabel(String text, int horizontalAlignment)中的参数???
- 怎么样才能做出下拉菜单的效果
- 关于java中Int等类型装箱时发生的奇怪现象
- 如何用正则表达式查询字符串中的单词?
- 10000个数求第2大的数,不许用排序算法.谁有没有什么好的方法??
异常被fun方法消化掉了,main函数没有察觉到
try{
throw new NullPointerException();
}catch(Exception e){
System.out.println("第一个try块!");
throw e; // 把异常信息抛出
}