第八天

package exception;

public class Test000 {
public static void main(String[] args) {
hhh(100);//方法内已经使用try,catch抛出捕获异常。直接使用方法就行。
}

static void hhh(int a){ //方法内用catch捕获异常,不用继续往上抛出
    try {
        if (a > 10) {
            throw new Exception();
        }
       System.out.println("ok");
    } catch (Exception e) {
        System.out.println("这是一个异常");
    }
}

}

posted @ 2024-01-31 20:55  学java的阿驴  阅读(12)  评论(0)    收藏  举报