测试可以,public class a2{ public static int a2(){ try{ System.out.println("dd1"); throw new Exception("111"); } catch(Exception e){ System.out.println("**************"); }finally{ return 5; } }
public static void main(String []args){ int b = a2.a2(); System.out.println(b); } }
应该可以,finally{}里的东西是不管try{}里的代码异常不异常都会执行的。
应该不可以.throw之前,他会执行finally{}体,执行到return时,程序就结束了.
代码如下, public class TT { public static void main(String[] args) { try { int i = new TT().a2(); //System.out.println(i); } catch (Exception e) { System.out.println("sss"); } } int a2(){ try{ System.out.println("dd1"); throw new Exception();
try{}
catch()下不就行了
public static int a2(){
try{
System.out.println("dd1");
throw new Exception("111");
}
catch(Exception e){
System.out.println("**************");
}finally{
return 5;
}
}
public static void main(String []args){
int b = a2.a2();
System.out.println(b);
}
}
public class TT
{ public static void main(String[] args)
{
try
{
int i = new TT().a2();
//System.out.println(i);
} catch (Exception e)
{
System.out.println("sss");
}
} int a2(){
try{
System.out.println("dd1");
throw new Exception();
}finally{
return 5;
}
}} 不能打印异常中的sss字符。取消注释可以打印返回值5所以只能返回值