package 实训;
public class 实训7lichenglong {
public static void main(String[] args) {
// TODO 自动生成的方法存根
try { //尝试
int result = (4/0); //除数为零,跳转divide方法
System.out.println(result);//输出异常
}catch(ArithmeticException e) {//捕捉异常并处理
System.out.println("小学生都笑哭了:除数不能为0!!!");//输出异常处理
}
}
//下面的方法实现了两个整数相除 并使用throws关键字声明抛出
public static int divide(int x,int y) throws ArithmeticException {//抛出异常
int result =x/y; //x除y的结果
return result;//返回x除y的结果
}
}