Re: How to centrally handle common exceptions from the databsae layer?
Since I did not hear any response, I would like to ask folks here, humbly, one more time. Am I asking the right question? Or Is my question confusing or unclear? Here is some background info why I am asking this quesiton. I did a spring web app before. I have a base form controller and its onSubmit method contains an abstract method as follows: public abstract ModelAndView doOnSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception; This base form controller's onSubmit centrally handles exceptions thrown from the service layer (most often the erros are database errors) and each specific form controller that inherits the base form controller handles business related to the specific form. In this way, I only need to do it once for handling errors and display right messages in user interface. Hope this helps. I really would like to hear from folks here about how to do the right thing. Best, David --- On Sun, 4/11/10, David Chang david_q_zh...@yahoo.com wrote: From: David Chang david_q_zh...@yahoo.com Subject: How to centrally handle common exceptions from the databsae layer? To: users@wicket.apache.org Date: Sunday, April 11, 2010, 11:38 AM I am hoping to understand how to write a good wicket app regarding handling exceptions from the databsae layer? For a wickt form, I can have the following to handle user submission: @Override protected void onSubmit() { User u = getModelObject(); userDao.saveUser(u); setResponsePage(Results.class); } For a wikcet web app, I can have many forms. But what is the best way to handle common database exceptions such as foreign key constraint violation, larger than a column width, etc. and displaying meaningful error messages? I could easily add try/catch around userDao#saveUser to handle them, but that would be bad in terms of code replication and maintenance. It may be good to handle in a central place. How do you deal with this issue in your wicket apps? Thanks for input! Best. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to centrally handle common exceptions from the databsae layer?
Those type of exceptions should be guarded against in your code (with validators, etc.). You shouldn't typically want to see them in production. I don't do anything special to handle unchecked exceptions for database problems because it's usually one of the following issues: 1. My code isn't working properly, meaning I'm not guarding against, so my code needs to be fixed. 2. The database is hosed and I can't do anything about it. On Sun, Apr 11, 2010 at 11:38 AM, David Chang david_q_zh...@yahoo.com wrote: I am hoping to understand how to write a good wicket app regarding handling exceptions from the databsae layer? For a wickt form, I can have the following to handle user submission: @Override protected void onSubmit() { User u = getModelObject(); userDao.saveUser(u); setResponsePage(Results.class); } For a wikcet web app, I can have many forms. But what is the best way to handle common database exceptions such as foreign key constraint violation, larger than a column width, etc. and displaying meaningful error messages? I could easily add try/catch around userDao#saveUser to handle them, but that would be bad in terms of code replication and maintenance. It may be good to handle in a central place. How do you deal with this issue in your wicket apps? Thanks for input! Best. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
How to centrally handle common exceptions from the databsae layer?
I am hoping to understand how to write a good wicket app regarding handling exceptions from the databsae layer? For a wickt form, I can have the following to handle user submission: @Override protected void onSubmit() { User u = getModelObject(); userDao.saveUser(u); setResponsePage(Results.class); } For a wikcet web app, I can have many forms. But what is the best way to handle common database exceptions such as foreign key constraint violation, larger than a column width, etc. and displaying meaningful error messages? I could easily add try/catch around userDao#saveUser to handle them, but that would be bad in terms of code replication and maintenance. It may be good to handle in a central place. How do you deal with this issue in your wicket apps? Thanks for input! Best. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org