标题: 异常问题,求解决 [打印本页] 作者: 多此一举 时间: 2014-7-4 20:26 标题: 异常问题,求解决 class Demo {
int div(int a, int b) {
if (b == 0) {
throw new ArithmeticException("被零除了");
}
return a / b;
}
}
public class ExceptionDemo {
public static void main(String[] args) {
Demo d = new Demo();
try {
int num = d.div(4, 0);
System.out.println(num);
} catch (Exception e) {
System.out.println(e.toString());
}