class SelfException extends Exception {
SelfException(){super();}
SelfException(String st){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);}
}
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("程序结束");
}
}
那位仁兄能不能详细的介绍一下这段代码的执行过程
2。然后从main开始
3。当执行到throwDemo函数时,创建SelfException对象
4。此时转到执行SelfException的父类的构造函数,然后执行它的构造函数
5。抛出异常,之后被捕获
6。由于没有finally,所以函数结束