自定义异常小栗子 忘记可以看看有记起来了 哎我就是玩

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt();
try {
sanjiao(a,b,c);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

public static void sanjiao(int a, int b, int c) throws IllegalArgumentException {
if((a + b) > c && (a + c) > b && (b + c) > a) {
System.out.println("a :" + a + " -- " + "b :" + b + " -- " + "c :" + c);
}else {
throw new IllegalArgumentException("a,b,c 不能构成三角形");
}
}
}
/*下面构造一个自定义异常*/
class IllegalArgumentException extends Exception {
public IllegalArgumentException() {
super();
}

public IllegalArgumentException(String msg) {
super(msg);
}

}

posted @ 2021-05-07 10:57  咸瑜  阅读(63)  评论(0编辑  收藏  举报