class SelfException extends Exception {
SelfException(){super();}
SelfException(){super(st);}
}
class jex7_11{
static int throwDemo(String st)throws SelfException{
if(st.equals("DEF")){throw new SelfException("a DEF");}
if(st.equals("ABC")){
System.out.println("throwDemo("+st+")没有抛出异常");}
return st.length();
}
public static void main(String args[]){
for(int i=0;i<arg.length;i++){
try{
System.out.println("长度:"+throwDemo(args[i]));
System.out.println("*******");
}
catch(SelfException e){
System.out.print("throwDemo("+argsp[i]+")抛出类型为"+e.getClass());
System.out.println(",异常信息是"+e.getMessage()+"的异常");
}
}
System.out.println("程序结束");
}
}
这段代码不是很理解....有谁能解释解释
SelfException(){super();}
SelfException(){super(st);}
}
class jex7_11{
static int throwDemo(String st)throws SelfException{
if(st.equals("DEF")){throw new SelfException("a DEF");}
if(st.equals("ABC")){
System.out.println("throwDemo("+st+")没有抛出异常");}
return st.length();
}
public static void main(String args[]){
for(int i=0;i<arg.length;i++){
try{
System.out.println("长度:"+throwDemo(args[i]));
System.out.println("*******");
}
catch(SelfException e){
System.out.print("throwDemo("+argsp[i]+")抛出类型为"+e.getClass());
System.out.println(",异常信息是"+e.getMessage()+"的异常");
}
}
System.out.println("程序结束");
}
}
这段代码不是很理解....有谁能解释解释
SelfException(){super();}
SelfException(String st){super(st);}
}
public class jex7_11{
static int throwDemo(String st)throws SelfException{
if(st.equals("DEF")){throw new SelfException("a DEF");}
if(st.equals("ABC")){
System.out.println("throwDemo("+st+")没有抛出异常");}
return st.length();
}
public static void main(String args[]){
for(int i=0;i<args.length;i++){
try{
System.out.println("长度:"+throwDemo(args[i]));
System.out.println("*******");
}
catch(SelfException e){
System.out.print("throwDemo("+args[i]+")抛出类型为"+e.getClass());
System.out.println(",异常信息是"+e.getMessage()+"的异常");
}
}
System.out.println("程序结束");
}
}
长度:5
*******
程序结束