创建一个自定义异常类
具体代码如下:
package keshanglianxi26_1;
public class QianBuGouException extends RuntimeException {
public QianBuGouException(){}
public QianBuGouException(String s){
super(s);
}
}
package keshanglianxi26_1;
import java.util.Scanner;
public class YinHangQuQian {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入取钱金额:");
int b = sc.nextInt();
QianShuCheack(b);
}
public static void QianShuCheack(int b){
int 余额 = 1000;
if(b<=余额){
System.out.println(b);
}else{
throw new QianBuGouException("余额不足");
}
}
}
|
|