"No exception is not allowed."
I am generating a report Checkstyle
embedded in the maven site and for one of the problems it indicates that Catching exception is not allowed
. How can I fix this problem? I just don't just want to remove the code, and if I have no other alternatives to fix this issue.
public void contextInitialized(ServletContextEvent event) {
super.contextInitialized(event);
ServletContext context = event.getServletContext();
setupContext(context);
LoggingHandler logging = (LoggingHandler) AppContext.getBean( "loggingHandler" );
try {
loadClientUserData( context, logging );
loadMBeans( context, logging );
} catch (Exception e) {
throw new RuntimeException( "Error during startup of service !!!" );
}
}
I am still studying Java
so any guidance would be appreciated.
thank
What do you warn that agility Exception
is a bad idea. Exception
is the most common type of exception you can catch. You basically say, "What a problem, I can handle this." It is not true. There can be a lot of weird and wonderful problems out there: keyboard interruptions, full disk space, the list goes on.
You said it loadClientUserData
throws ManagerException
, so you should catch that specific exception and leave any others to propagate further:
try {
loadClientUserData( context, logging );
loadMBeans( context, logging );
} catch (ManagerException e) {
throw new RuntimeException( "Error during startup of service !!!" );
}
For more information, see the following questions:
source to share