编译时间错误

时间:2014-06-01 16:53:44

标签: exception

请告诉我实际发生的事情 - 实际上编译时错误在这里,但为什么?

public class A
{ 
   static int test(String s1)
   {
      try { 
         return 1;
      }
      catch(NumberFormatException e){ 
         return 2; 
      }
      return 3;
   }
}

1 个答案:

答案 0 :(得分:0)

try { 
   return 1;
}
catch(NumberFormatException e){ 
   return 2; 
}

...将始终返回1(如果尝试可以抛出该异常,则返回2),所以你的陈述......

return 3;

...始终无法访问,并且会出现编译错误。