package com.lovecoding.day13.exception02;

import org.junit.Test;

public class Test01 {

    @Test
    public void fun4() throws InterruptedException {

        int i = 0;
        Thread.sleep(1000);
        System.out.println(i++);

    }

    @Test
    public void fun3() /*throws Exception*/ { //jvm
        //抛出异常  Exception 需要调用者解决
        //解决 try catch 继续抛出
        try {
            fun2();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public void fun2() throws Exception{
        int i = 1/0;
    }

    @Test
    public void fun1(){
        //try catch
        // ctrl + alt + t 生成 try catch
        try {
            int i = 1/0;
        } catch (ArithmeticException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        } catch (Exception e){
            e.printStackTrace();
            System.out.println(e.getMessage());
        }

        // try  可以出现错误的代码
        // catch 捕获异常 输出异常信息
        // 代码可以向下执行
        System.out.println("hello");

    }
}
