62,614
社区成员
发帖
与我相关
我的任务
分享
public class Test{
public static void main(String[] args){
Test TT = new Test();
try{
//TT.num(-1);
}catch (MyExceptions1 ME1){
System.out.println(ME1.getMessage());
}catch (MyExceptions2 ME2){
System.out.println(ME2.getMessage());
}
}
void num1(int i) throws MyException1{
if(i < 0){
throw new MyException1("数字太小;");
}
}
void num2(int i) throws MyExceptions2{
if(i > 0){
throw new MyException2("数字太大;");
}
}
class MyException1 extends Exception{
//private int id = 1;
public MyException1(String s){
super("数字太小;");
}
}
class MyException2 extends Exception{
//private int id = 2;
public MyException2(String s){
super("数字太大;");
}
}
}
public class bb{
public static void main(String[] args){
bb TT = new bb();
try{
TT.num(-1);
}catch (MyException1 ME1){
System.out.println(ME1.getMessage());
}catch (MyException2 ME2){
System.out.println(ME2.getMessage());
}
}
void num(int i) throws MyException1,MyException2{//这样不是更好?
if(i < 0){
throw new MyException1("数字太小;");
}
if(i > 0){
throw new MyException2("数字太大;");
}
}
class MyException1 extends Exception{
//private int id = 1;
public MyException1(String s){
super("数字太小;");
}
}
class MyException2 extends Exception{
//private int id = 2;
public MyException2(String s){
super("数字太大;");
}
}
}