当前位置: 技术问答>java相关
thread考题一道??,,??,
来源: 互联网 发布时间:2015-03-13
本文导语: try{ method(); some code1 } catch( IOException a){ some code2 } finally{ some code3} some code4 what will be excecuted if the method throws NullPointerException? some code 1 some code 2 some code 3 some code 4 some code 4为何不行???清高手解...
try{
method();
some code1
}
catch( IOException a){
some code2
}
finally{
some code3}
some code4
what will be excecuted if the method throws NullPointerException?
some code 1
some code 2
some code 3
some code 4
some code 4为何不行???清高手解释
method();
some code1
}
catch( IOException a){
some code2
}
finally{
some code3}
some code4
what will be excecuted if the method throws NullPointerException?
some code 1
some code 2
some code 3
some code 4
some code 4为何不行???清高手解释
|
因为他要找能够捕获NullPointerException的地方,所以,除了finally例的外,其他都没办法执行。
|
如果发生异常
比如method()里
后面的代码some code1是不会执行的,相当于程序出错.
some code 4也一样
比如method()里
后面的代码some code1是不会执行的,相当于程序出错.
some code 4也一样
|
不能捕捉到NullPointerException,所以程序出错中断
|
注意一下,finally里只是一个程序块,不代表执行完里面的东西后会接着执行代码的下一行。
finally看以看作一个陷阱/中断.
finally看以看作一个陷阱/中断.