class MyException2 extends Exception {
String xinxi;
MyException2 (int m){
xinxi="数据有误,超过1000";
}
public String toString(){
return xinxi;
}
}
class Student
{
public void speak(int m) throws MyException2
{
if(m>1000)
{
MyException2 exception=new MyException2(m);
throw exception;
}
System.out.println("数据正确!"+m);
}
}
public class Test {
public static void main(String args[]){
Student s=new Student();
try
{
//s.speak(999);
s.speak(9999);
//s.speak(946);
}
catch(MyException2 e)
{
System.out.println(e.toString());
}
}
}