javaSE之运行时异常和编译时异常
2020-12-13 04:31
标签:sys etag sage col string exce ring 编译 pac 运行时异常继承自RuntimeException; 编译时异常继承自Exception; 看看前面的视频,关于运行时异常和编译时异常; ...未完待补充 javaSE之运行时异常和编译时异常 标签:sys etag sage col string exce ring 编译 pac 原文地址:https://www.cnblogs.com/shijinglu2018/p/11111847.htmlpackage foundationEnhance;
public class Person {
private int age;
public Person(int age) {
super();
if(age){
throw new ageException("年龄不可以为负数!");
}
this.age = age;
}
public int getAge() {
return age;
}
public void setAge(int age) {
if(age){
throw new ageException("年龄不可以为负数!");
}
this.age = age;
}
}
package foundationEnhance;
public class testPerson {
public static void main(String[] args) {
Person p=new Person(-1);
p.setAge(-2);
System.out.println(p.getAge());
}
}
package foundationEnhance;
public class ageException extends RuntimeException{
public ageException() {
}
public ageException(String message) {
super(message);
}
}
上一篇:多线程聊天室