import java.util.Scanner;
class GradeException extends Exception {
GradeException(String msg) {
super(msg);
}
}
public class GradeDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
try {
System.out.println("你是几年级的学生?");
int i = sc.nextInt();
if (i < 1 || i > 3) {
GradeException e = new GradeException("输入了不存在的年级!");
throw e;
} else {
System.out.println("你是" + i + "年级的学生!");
}
} catch (GradeException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class GradeException extends Exception {
GradeException(String msg) {
super(msg);
}
}
public class GradeDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
try {
System.out.println("你是几年级的学生?");
int i = sc.nextInt();
if (i < 1 || i > 3) {
GradeException e = new GradeException("输入了不存在的年级!");
throw e;
} else {
System.out.println("你是" + i + "年级的学生!");
}
} catch (GradeException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}