【发布时间】:2012-10-16 18:35:43
【问题描述】:
在玩 Java 中的异常处理时,我注意到当 在 Java 的 catch 块中进行了一些非法的运行时操作。
这是语言中的错误还是我遗漏了什么? 有人可以调查一下吗 - 比如为什么从 catch 块中没有抛出异常。
public class DivideDemo {
@SuppressWarnings("finally")
public static int divide(int a, int b){
try{
a = a/b;
}
catch(ArithmeticException e){
System.out.println("Recomputing value");
/* excepting an exception in the code below*/
b=0;
a = a/b;
System.out.println(a);
}
finally{
System.out.println("hi");
return a;
}
}
public static void main(String[] args) {
System.out.println("Dividing two nos");
System.out.println(divide(100,0));
}
}
【问题讨论】:
标签: java exception-handling divide-by-zero