public class Demo03 {
static String[] usernames = {"张三", "李四", "王五"};
public static void main(String[] args) throws RegisterException {
String logicname = new Scanner(System.in).next();
checkUsername(logicname);
}
public static void checkUsername(String logicname) throws RegisterException{
for (String name : usernames) {
if(name.equals(logicname)){
throw new RegisterException("该用户已经被注册");
}
}
System.out.println("恭喜您,注册成功");
}
private static class RegisterException extends Exception {
public RegisterException(String 该用户已经被注册) {
super(该用户已经被注册);
}
}
}
自定义异常报错
最新推荐文章于 2022-10-27 17:47:08 发布