0
public class ExceptionExample {

    public static void main(String args[]) {

        try{}
        //catch(SQLException e){} //Compile time Error
        catch(Exception e){} // No Error
    }
}
jmj
  • 232,312
  • 42
  • 391
  • 431
Jeetendra Sahu
  • 89
  • 1
  • 1
  • 4
  • `RuntimeException`s need not be mentioned in the method signature, therefore there's no way for the compiler to check, if an method call could throw a certain `RuntimeException` or not, but for non-`RuntimeException`s its different. But the answer to your question is simply: "Because the java specification says so." – fabian May 21 '15 at 18:48

2 Answers2

1

because SQLException is not a RuntimeException, i.e. no code written in try block can throw it without declaring it,

where Exception could be a RuntimeException

jmj
  • 232,312
  • 42
  • 391
  • 431
0

Checked exceptions must call a method the actually throws that exception, in the try clause.

Mordechai
  • 14,445
  • 1
  • 39
  • 78