java - How should you handle exceptions that occur below the level of the Controller in a Spring MVC web app? -


Assume that you've got Spring Web App with this type of structure:

  Com / myapp / controller / model / service /  

How can you manage the exceptions below the controller level?

Should you create methods in the model and throw your exception to the service layer controller layer?

What do you do with them after reaching the controller?

Do you always show the same error page to users but write a detailed exception to the log files?

It depends very much on the concrete case:

  • With the exception message you send an exception message (translated by a few exception translation mechanisms for a human-readable representation) - for example "sending email failed, please try again later"

  • Exception can not be retrieved, you can redirect to a page that shows human-readable explanation

  • You can redirect to a normal 500 page which says, "Oh, something went wrong

  • < / Li>


Comments