int a2(){
  try{
    System.out.println("dd1");
    throw new Exception();
  }finally{
     return 5;
  }
}这样写的函数能不能即返回函数又抛出异常?

解决方案 »

  1.   

    不能吧 你试下就知道了
    try{}
    catch()下不就行了
      

  2.   

    测试可以,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);
    }
    }
      

  3.   

    应该可以,finally{}里的东西是不管try{}里的代码异常不异常都会执行的。
      

  4.   

    应该不可以.throw之前,他会执行finally{}体,执行到return时,程序就结束了.
      

  5.   

    代码如下,
    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所以只能返回值