自定义异常小栗子 忘记可以看看有记起来了 哎我就是玩
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);
}
}
本文来自博客园,作者:咸瑜,转载请注明原文链接:https://www.cnblogs.com/bi-hu/p/14738285.html