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()); } } }
11-09
1万+
05-07
4219
02-23
5004
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交