Hi every body..
I am developing an application. To check the code standards i am running pmd which i have integrated with my IDE.
On each of the servlet i am using try catch as follows
well it means that my all case statements are in try catch block.
Problem 1st But when i ran PMD for this file....it gives an error saying
"Avoid using catch-all blocks; except in 'main()'."
well i am not getting the meaning of this result.
does it mean that for each case i should put try-catch seperately...??
can any body guide me please.
Problem 2nd
In finally block i am using out.close() to free the resources.
if use System.out.close() ..... will it have the same effect or using out.close() is necessary.
Thanks.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
"Avoid using catch-all blocks; except in 'main()'."
Obviously PMD doesn't know about servlet architecture. Ignore that advice. Your arrangement will work fine, but I would add the actionSource variable to the exception logging message and think about a better way to notify the client that there was a problem.
In finally block i am using out.close() to free the resources.
if use System.out.close() ..... will it have the same effect or using out.close() is necessary.
NOT the same! System.out is shared by all the servlets and the servlet container. You should only close streams you open.
It's also quite common to register a common handler in the deployment descriptor and not catch anything in the servlets. If you are planning to handle exceptions using a common means, then there's no need to try/catch in every servlet.