Reputation: 1892
Sorry if the questions have already been asked, but I can't find a correct answer. I'm using Hibernate and Spring in my project and I want to catch and deal with hibernate exceptions if they happened. I've read that Spring could help me with it, but I don't really understand the documentation.
Spring seems to translate these exceptions into others Exceptions but I can't find in which ones to be sure to catch them all?
Upvotes: 0
Views: 171
Reputation: 44398
There is in the Spring page the tutorial about handling exeptions.
You can invoque the exception by throwing it when an error occurs:
throw new MyHibernateException(id);
Here is your custom exception:
@ResponseStatus(HttpStatus.NOT_FOUND)
public class MyHibernateException extends RuntimeException { }
You can set a face to your exception in the web.xml
:
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/views/errors/404.jsp</location>
</error-page>
Upvotes: 1