【java】异常处理机制

抛出异常
捕获异常

关键字
try,catch,finally,throw,throws
假设要捕获多个异常,从上到下要是:从小到大的捕获
    
public class Test {
    public static void main(String[] args) {
        int a = 1;
        int b =0;
        try{ //监控区域
            System.out.println(a/b);
        }catch (ArithmeticException e){ //想要捕获的异常类型
            System.out.println("出现异常");
        }finally { //处理善后工作
            System.out.println("finally");
        }

    }
}

 

posted @ 2022-04-10 21:48  hanyr  阅读(23)  评论(0)    收藏  举报