📄 myexception.java
字号:
class CCOutOfAge extends Exception
{
public String toString(){
return "data is out of rang";
}
}
class COutOfAge{
private int age=0;
public void setAge(int a) throws CCOutOfAge
{
if ((a<0) || (a>120)) {
throw new CCOutOfAge();
}
else
age=a;
}
public void showage()
{
System.out.println("age is "+ age);
}
}
public class myexception{
public static void main(String args[]) {
int a = -5;
COutOfAge age=new COutOfAge();
try {
age.setAge(a);
}
catch(Exception e) {
System.out.println(e.toString());
}
age.showage();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -