work076.java
package test04;
public class work076
{
public static void main(String[] args)
{
try
{
Student1 stu1 = new Student1();
stu1.speak(1002);
} catch (MyException4 e)
{
System.out.println(e.getMessage());
}
}
}
class Student1
{
public void speak(int m) throws MyException4
{
if(m > 1000)
{
throw new MyException4("数值超出1000");
}
}
}
class MyException4 extends Exception
{
public MyException4(String errorString)
{
super(errorString);
}
}