Suppose that we have developed a website in Struts 2, Hibernate, MySQL and we have added few try/catch
blocks here are there which encloses database calls via Hibernate.
My question is:
Inside the catch block l am sending appropriate message to a logger. Here we can't use
System.out.println
as its a webpage, what else can be done to alert the user about exception?As a part of testing I changed the
hibernate.cfg.xml
and input wrong database password so as to simulate the database crash scenario.
as I expected It threw error:
javax.servlet.ServletException: Filter execution threw an exception
java.lang.NoClassDefFoundError: com_cenqua_clover/CoverageRecorder
my.com.employee.<init>(employee.java:29)
com.action.employeeAction.<init>(employeeAction.java:23)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
java.lang.Class.newInstance0(Class.java:355)
java.lang.Class.newInstance(Class.java:308)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:119)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139)
com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109)
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:288)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.20 logs.
and from users perspective this is not desirable right, so how to tackle such problems. I am using Eclipse Juno, Windows XP, MySQL 5.5.