各位帮帮忙看一下我的程序(异常处理中的问题),期待请教!谢谢!
import java.util.Scanner;class MyException extends Exception{
MyException(){
super("面试年龄不符合!");
}
}
class LaborialStaff{
void get(int age){
if(age<18||age>40){
throw new MyException();
}else{
System.out.println("符合面试要求!");
}
}
}
class MiddleManagement{
void get(int age){
if(age>28&&age<50){
System.out.println("符合面试要求!");
}else{
throw new MyException();
}
}
}
class SeniorManagement{
void get(int age){
if(age>35&&age<65){
System.out.println("符合面试要求!");
}else{
throw new MyException();
}
}
}
public class Recruitment_3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int age1,age2,age3;
int i;
try{
System.out.println("请输入你要应聘的职位,1为普工,2为中层管理员,3为高级管理员.谢谢!");
Scanner sc=new Scanner(System.in);
i=sc.nextInt();
switch(i){
case 1:
System.out.println("你要应聘的是普通员工,请输入你的年龄:");
Scanner ss=new Scanner(System.in);
age1=ss.nextInt();
LaborialStaff a=new LaborialStaff();
a.get(age1);
break;
case 2:
System.out.println("你要应聘的是中层管理人员,请输入你的年龄:");
Scanner mm=new Scanner(System.in);
age2=mm.nextInt();
MiddleManagement b=new MiddleManagement();
b.get(age2);
break;
case 3:
System.out.println("你要应聘的是高级管理人员,请输入你的年龄:");
Scanner xx=new Scanner(System.in);
age3=xx.nextInt();
SeniorManagement c=new SeniorManagement();
c.get(age3);
break;
default:
System.out.println("Input Error!");
break;
}
}catch(MyException ex){
System.out.println(ex.getMessage());
}
}
}
//错误就在标记的地方了,为啥这样抛出的自定义异常不能捕捉,请个位帮帮忙看看,谢谢!