No exception of type DataAccessException can be thrown; an exception type must be a subclass of Throwable

前端 未结 5 873
旧巷少年郎
旧巷少年郎 2021-01-17 13:42

My source code like below. It has a error, \"No exception of type DataAccessException can be thrown; an exception type must be a subclass of Throwable\".

I can\'t un

相关标签:
5条回答
  • 2021-01-17 14:08

    Your DataAccessException is not a subclass of Throwable class (extends Throwable). It should be, and without this inheritance, your code is not compilable with the current throws clause.

    Here is an example: http://www.osix.net/modules/article/?id=754

    0 讨论(0)
  • 2021-01-17 14:12

    I was facing same problem. What I have done wrong was I have created Exception class(by mistake) of my own. In other programs I was trying to extend Exception class(default) but complier(eclipse)was loading user defined Exception class giving me same error. So please make sure you are not overriding any default class.

    0 讨论(0)
  • 2021-01-17 14:13

    This can happen if some class in the type-hierarchy of the exception is not on the class-path. In that case, its not possible to verify whether the exception really extends Throwable, whether it is a checked one or not, etc. Hence the errors. e.g superclass of Dataaccessexception : NestedRuntimeException may be missing from the class-path as it is in a differnt jar i.e. spring-core.

    0 讨论(0)
  • 2021-01-17 14:14

    This means that in your getUserInfo() method there is no code that throws that exception. So just remove the throws clause from your method declaration.

    0 讨论(0)
  • 2021-01-17 14:26

    I had this same issue when I upgraded to 5.X.X version. I have added Spring-core.jar file and it worked fine for me. Just adding this here because it may help some one. Spring txn jar , dao jar and spring core are must.

    0 讨论(0)
提交回复
热议问题