public class Exception {
int num(int x, int y) { return x / y; }public static void main(String[] args) {
Exception ex = new Exception(); try{ //需要被检测的代码 int n=ex.num(3, 0); System.out.println(n); //不会被执行 } catch (ArithmeticException e) { //处理异常代码 System.out.println(e.toString()); } finally{ //一定会执行的语句 System.out.println("over"); } }}