代码有误
这是我重新写过的
class MyException extends Exception{
static int InstanceNumber=0;
MyException(String message){super(message)}
void run(int j) throws MyException{
if (j%2!=0){
InstanceNumber++;
throw new MyException();
}
}
String Say(){
return "I'm MyException."+InstanceNumber+"!";
}
}
public class UseMyException{
public static void main (String[] args){
int i;
MyException My=new MyException();
System.out.println ("test my exception");
for (i=0;i<7;i++){
try{
My.run(i);
}catch(MyException e){
System.out.println("A exception\n"+My.Say());
}
System.out.println("test end.");
}
}
}
这是我重新写过的
class MyException extends Exception{
static int InstanceNumber=0;
MyException(String message){super(message)}
void run(int j) throws MyException{
if (j%2!=0){
InstanceNumber++;
throw new MyException();
}
}
String Say(){
return "I'm MyException."+InstanceNumber+"!";
}
}
public class UseMyException{
public static void main (String[] args){
int i;
MyException My=new MyException();
System.out.println ("test my exception");
for (i=0;i<7;i++){
try{
My.run(i);
}catch(MyException e){
System.out.println("A exception\n"+My.Say());
}
System.out.println("test end.");
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货