I am trying to display the exception occurred in the controller on the view layer. For this I have setup a try catch block like:
public String persistUserData( )
{
try
{
//Make DB Call
// Update DB and get new Data
model.addAttribute( "updatedData", data );
throw new Exception("Creating an Exception");
}
catch(Exception e)
{
model.addAttribute("myException", ex.getClass());
}
return "myPage.jsp";
}
In my view I am trying to print it with ${myException}, but its not printing anything. What is going wrong here?
${myException}will calltoString()on exception, if it does not have any message, you will get null/empty string. Try:model.addAttribute("myException", e.getClass());