我对java的异常检查感到困惑
Checked Exception需要在编译时使用try,catch和finally关键字进行处理,否则编译器将标记错误
阅读更多:http://javarevisited.blogspot.com/2013/06/10-java-exception-and-error-interview-questions-answers-programming.html#ixzz3pk6OBSrj
我的问题是:我们都知道" NoSuchMethodExcepion "被检查异常,并且考虑上面的语句,这是否意味着每当我尝试调用一个方法时,我应该使用try,catch来包含调用这样的方法代码
try{
callingMethod();
}
catch(Exception){
}
Run Code Online (Sandbox Code Playgroud)
但事实上,我不需要这样做吗?那么首先给出的陈述的真正含义是什么?谢谢你回答我的问题.
public class Main{
public static void main(String[] args){
int a = 0;
int[] b = new int[5];
int c = 3;
b[a] = a = 3;//a is covered with 3, why the entry assigned with 3 is b[0] instead of b[3]
System.err.println(b[0]);
System.err.println(b[3]);
System.err.println(b[a]);
}
}
Run Code Online (Sandbox Code Playgroud)
输出是:
3
0
0
Run Code Online (Sandbox Code Playgroud)
我想原因可能是第五个像中间变量缓冲区,但我仍然不太确定该语句是如何b[a] = a = 3;工作的.