在jBuilder2006中有个方法返回某个类型的数据, 我在try快中有return语句,但是在整个方法的最后老是出错说缺少返回值。 
如下是个大概的模式。 public int name(){ 
try { 
return 2; 
} catch (Exception e){ } 
}

解决方案 »

  1.   

    public int name() {
    try {
    return 2;
    } catch (Exception e) {
    return 0;
    }
    }
      

  2.   

    对每一个可能的分支分别return,这样保证程序能编译,如果返回值是int型,在异常处理中就return 0或者别的特殊int,如果是别的引用型,就直接返回null
      

  3.   

        public int name() {
            try {
                return 2;
            } catch (Exception e) {
                return "";
            }
        }
      

  4.   

    catch 语句后也要return才行
      

  5.   

    ls的人都说了,或者象这个一样也行
    public   int   name(){   
    try   {   
     
    }   catch   (Exception   e){   }   return   2;  
    }
      

  6.   

    public int name(){       
    try{ }catch (Exception       e){


    return 2;  //一般return放在最好返回
    }
      

  7.   

    够狠, return还要放在catch里?