第3楼 2007-05-22 20:12 梦幻天空号 写道:
由于日期判断内容很多,所以我没有完善,不过大概的意思有了,希望能帮到你
定义一个异常类,我使用的是继承Exception你也可以继承Throwable
public class ExceptionClass extends Exception {
public ExceptionClass() {
super();
}
throws ExceptionClass {
if (month > 12 || month < 1 || day >31 || day < 1 ){
System.err.println("Illegal date!!");
}
}
}
实验
public class Main extends Exception {
public static void main(String[] args) {
ExceptionClass ec = new ExceptionClass();
try {
ec.invalidDate(2007,111,10);
}catch (ExceptionClass e){
e.printStackTrace();
}
}
}
写的很简单,希望起到抛砖引玉的效果