下面两段代码 throw new Exception();的下面都有语句,为啥第2个代码throw new Exception();语句在执行
foo(1);的时候却通过了不是说throw new Exception();语句下面不可以写语句的么?
第一个:
class examcry{
public static void func(){
try{
throw new Exception();
System.out.println("A");
}
catch(Exception e){
System.out.println("B");
}
}
public static void main(String[] args){
try{
func();
}
catch(Exception e){
System.out.println("C");
}
System.out.println("D");
}
}
第二个
class examcry20
{
public static String output="";
public static void foo(int i)
{
try{
if(i==1)
throw new Exception();
output+="1";
}
catch(Exception e){
output+="2";
return;
}
finally{
output+="3";
}
output+="4";
}
public static void main(String args[])
{
foo(0);
System.out.println(output);
foo(1);
System.out.println(output);
}
} |
|