I have two snippet of code :
class PreciseRethrow { public static void main(String[] str) { try { foo(); } catch (NumberFormatException ife) { System.out.println(ife); } } static private void foo() throws NumberFormatException { try { int i = Integer.parseInt("ten"); } catch (Exception e) { throw e; } } } and :
class PreciseRethrow { public static void main(String[] str) { try { foo(); } catch (NumberFormatException ife) { System.out.println(ife); } } static private void foo() throws NumberFormatException { try { int i = Integer.parseInt("ten"); } catch (Exception e) { throw new Exception(); } } } In second case I got compile error "Unhandled exception type Exception" when I throw new Exception () in catch clause. Can You explain me Why in first case everything is ok but in second i get compile error ? In both case I throw Exception but in second case i create new instance of exception (this in only difference beetwen this two examples). Thanks for help.