package day09;
public class IllegalAgeException extends Exception{
private static final long serialVersionUID = 1L;
public IllegalAgeException() {
super();
}
public IllegalAgeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
public IllegalAgeException(String message, Throwable cause) {
super(message, cause);
}
public IllegalAgeException(String message) {
super(message);
}
public IllegalAgeException(Throwable cause) {
super(cause);
}
}
package day09;
public class Prerson {
private int age;
public int getAge(){
return age;
}
public void setAge(int age)throws IllegalAgeException{
if(age<0||age>100){
throw new IllegalAgeException("年龄不合法!");
}
this.age=age;
}
}
|