编写自己的程序,创建自己的异常,对程序接受的数据输入进行异常的捕捉和处理

来源:百度知道 编辑:UC知道 时间:2024/06/28 12:50:06
急用,谢谢啊。请各位高手帮帮忙啊!

public class MyException extends Exception{
private String content;
public MyException(String content2) {
this.content=content2;
}

public String getContent()
{
return this.content;
}

}

public class studentScore {
public static void check(int a) throws MyException
{
if(a<0||a>100)
{
throw new MyException("成绩必须在0-100之间。");
}
}
public static void main(String args[])
{

int a[]=new int[10];
int n=0;
while(n<a.length)
{
System.out.println("请输入学生成绩:");
try
{
int temp;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
temp=Integer.parseInt(br.readLine());
try
{
check(temp);
a[n]=temp;
n++;
}
catch(MyException myExc)
{
System.out.println(myExc.getContent(