1

or are they the same ?

} catch (RuntimeException re) {
...
}

or

} catch (Exception e) {
...
}
Leo
  • 1,829
  • 4
  • 27
  • 51
  • 1
    Either is bad practice. Catch the specific exceptions you can handle. – Dodd10x Sep 28 '15 at 20:15
  • 1
    I think this help: http://stackoverflow.com/questions/19164020/why-doesnt-catching-exception-catch-runtimeexception – Renato Nati Sep 28 '15 at 20:16
  • RuntimeException and its subclasses are unchecked while Exception and its subclasses, excluding the RuntimeException and its subclasses are checked. unchecked methods have not to be declared in a method or have to been thrown by a class's constructor – Tom Wellbrock Sep 28 '15 at 20:22
  • 1
    If I may emphasize Dodd10x's point: Both of those are very bad practice. Both catch unchecked exceptions, which in almost all cases should never be caught, because they expose programmer errors. Catching them won't make your code work, it will just make it considerably harder to understand why your code doesn't work. – VGR Sep 28 '15 at 20:24
  • @VGR thats not true! Only RunetimeException and its subclasses are unchecked, proven through the documentation. Or is it just a bad choice of words.. well I kinda get what you want to say – Tom Wellbrock Sep 28 '15 at 20:25

1 Answers1

4

RuntimeException extends Exception, so Exception is strictly broader. (And they're not the same; e.g. IOException is an Exception but not a RuntimeException.)

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413
  • 1
    Additionally to his answere the Sun' documentation is your friend: http://docs.oracle.com/javase/7/docs/api/java/lang/RuntimeException.html – Tom Wellbrock Sep 28 '15 at 20:15