handling exception in formBackingObject
what is the proper way to handle an exception in formBackingObject of my subclass of SimpleFormController?
currently I retrieve some data to be displayed in this method and the data layer may throw an exception. I would like to catch it and then display it on a page. i.e.:
protected Object formBackingObject(HttpServletRequest request) throws Exception {
String orderId = RequestUtils.getRequiredStringParameter(request, "orderId");
try {
return (Order)service.getOrder(orderId);
} catch (LockedException e) {
//what to do now?
}
}
ModelAndViewDefiningException
The only thing you can really do is eat the exception (bad) or throw a new exception. You might want to take a look at org.springframework.web.servlet.ModelAndViewDefini ngException. This allows to to specify a model and view to "handle" your exception.
Re: ModelAndViewDefiningException
I think this will help me a lot. Thank you.