public class userService{
    public static void main(String[] args) {
        int a = 1;
        int b = 0;
        try {
            System.out.println(a/b);
        } catch (Exception e) {
            System.out.println("ArithmeticException");//可以自己写异常,也可以用以下方法
            e.printStackTrace();//打印错误的栈信息
        } finally {
        }
        try {//监控区域
            System.out.println(a/b);
        }catch(Error e){//捕获错误
        }catch(Exception e){//捕获异常
            System.out.println("分母不能为零!");
        }catch(Throwable e){//最高级
        }finally {//善后工作,可以不写。如scanner后,可以释放scanner占用的空间
            System.out.println("finally");
        }
    }
}
原文:https://www.cnblogs.com/jiabaolu/p/14860728.html