请问一下,我好想听过只要catch到exception后,就执行catch块里面的东西

来源:百度知道 编辑:UC知道 时间:2024/06/06 12:24:31
,以下的代码就执行不了了,可是这个明明可以执行啊
public static void main(String[] args) {
try {
Class.forName("AA");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
System.out.println("first。。。。");
}
System.out.println("two。。。。。");
}
,谢谢

上面抛出异常后,底下两句话都可以输出的啊?
我的意思是,即使不用finally,catch到异常后,接下来的代码不是还是会执行吗,比如上面的

都会执行的,那是因为你已经捕捉到异常了,如果你直接将异常抛给上层代码的话就不会执行下面的代码了,比如说将上面的代码改为

public static void main(String[] args) throws ClassNotFoundException{
Class.forName("AA");
System.out.println("two。。。。。");
}

下面的那段代码就不会执行了,因为出现了异常,程序自己不能解决,而交给了上层去了。你写的那个因为你已经将异常捕捉到了,并做了处理。当然程序会继续往下执行了。
希望以上讲解会对你有所帮助

如果你这么写的话:
public static void main(String[] args) {
try {
Class.forName("AA");
System.out.println("three。。。。。");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
System.out.println("first。。。。");
}
System.out.println("two。。。。。");
}
执行到catch以后,System.out.println("three。。。。。");这句话是不会执行的,而下面两句
System.out.println("first。。。。");
System.out.println("two。。。。。");
会执行

try
catch
finally
这是一个结构,先try,如果某一句出错就执行catch,但是始终会执行finally

请问哪里可以下载到Catch a falling star这首歌? 我老婆的腿只要不小心碰一下,过几十分钟后就紫了,请问是怎么回事? 请问一下轩逸1.6EX和轩逸2.0EX有什么区别啊? 我朋友的电脑开机运行到桌面,只要再点一下就死机了,请问是什么原因,如何解决? He got to the station too late to catch the train 请帮我分析一下这句的结构特别是to catch the train 我被我家小狗狗咬了一下,它去年打过狂犬,但是咬我只要破皮了,不用手挤不出血,请问用去打狂犬针吗? 想买联想旭日C430M-EX,用过的朋友给评价一下。 我的EX女朋友 我想请问一下,如何历史记录,让我浏览过的网页不保存到历史记录里面 谁能帮我翻译一下杜牧的《过华清宫绝句》?只要翻译就行,谢谢!