I have JSP with several the fields one of which is Date, server side as servlets. I have Date check at client side, and i want to make Date check at server side.
I have a method that convert Date from string, which is getted from request.
public static Date convertToDate (String s) throws ParseException {
return formatter.parse(s);
}
I use this method with try/catch
try {
Date date = Utils.convertToDate(request.getParameter("Date")));
} catch (ParseException e) {
//throw what? new Exception or ParseException or something else
throw new ParseException (request.getParameter("Date")+ "is not a Date");
}
Finally, I handle exception at controller servlet like
try {
//some methods that use method convertToDate
} catch (SomeException e) { //required right exception
response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
return;
}
Questions. Should I create new ParseException for adding information or create new exception like IncorrectDateException? Are there more suitable options for handling exception?
Thanks.