troubleshooting Question

Can we use Model addAttribute to handle errors in the UI ?

Avatar of Software Programmer
Software Programmer asked on
Java EEProgrammingJava
9 Comments1 Solution183 ViewsLast Modified:
Example Sample Code
@RequestMapping(value = "/add", method = RequestMethod.POST)
public ModelAndView addEmployee(Model model, EmpTO empTO, BindingResult bindingResult){
    try {
        empService.saveOrUpdateEmployee(empTO);
    } catch (Exception e) {
        if (e instanceof InvException) {
            model.addAttribute("error", ((InvException) e).getError());
        } else {
            model.addAttribute("error", PresentationUtil.handleApplicationRuntimeError(e));
        }
        return new ModelAndView("emp/save");
    }
    empTO = new EmpTO();
    return new ModelAndView("emp/home");
}

Questions:
---------------

1. Is the above is the correct approach?
2. Can we store the error code and description in a DB table or hard-coded string and let UI handles the error codes?
3. Is this is a standard industry practice?

Thanks
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros