7

Possible Duplicate:
why hibernate changed HibernateException to RuntimeException (unchecked)

What is the reason for keeping exception in spring and hibernate as unchecked exception?

Is only to reduce the cluttering while coding or there is some other design principal behind it?

Community
  • 1
  • 1
Jyotirup
  • 2,882
  • 9
  • 30
  • 38

3 Answers3

6

While dealing with most of the database exceptions, there is hardly anything developer can do (I mean write something in catch block to recover from exception). Like database connection problem, incorrect query or column don't exist in table etc problems.
So unchecked exceptions rescue developers from adding unnecessary catch blocks. If you want still you can catch desired unchecked exception and leave the rest of them which is not the case with checked exceptions.

Ajinkya
  • 22,324
  • 33
  • 110
  • 161
  • 1
    True.. The question then is how come jdbc missed this point and made most of the exception checked exception.... – Jyotirup Jul 15 '12 at 11:00
  • 2
    @Jyotirup: Dont know about jdbc but it loos like Hibernate and Spring learnt from jdbc's mistake. – Ajinkya Jul 15 '12 at 15:24
4

The checked versus unchecked Exception debate is an age old one. Both camps have strong proponents. As a team you should pick a style and stick to it.

Although I can only guess the rationale, apparently spring and hibernate favored the unchecked exception camp.

The debate is (among others) discussed in the question "In Java, when should I create a checked exception, and when should it be a runtime exception?".

Community
  • 1
  • 1
dvberkel
  • 663
  • 4
  • 16
1

what i think framework like Spring, Hibernate work arround java reflection . And reflection most of the exceptions are runtime exceptions.

amicngh
  • 7,831
  • 3
  • 35
  • 54