Verbose exception catch clauses
Background
I have a case where my logic requires surround with try/catch, I have a
lots of catch clauses, which makes my code a bit ugly. What I do in catch
clause is only log the error using log4j.
Question Is it ok to use one catch clause with parent exception type
instead of bunch of catch clauses? Instead of this:
try{
//some statements
} catch (KeyStoreException e) {
LOGGER.error(e);
} catch (CertificateException e) {
LOGGER.error(e);
} catch (NoSuchAlgorithmException e) {
LOGGER.error(e);
} catch (FileNotFoundException e) {
LOGGER.error(e);
} catch (IOException e) {
LOGGER.error(e);
} catch (UnrecoverableKeyException e) {
LOGGER.error(e);
} catch (NoPropertyFoundException e) {
LOGGER.error(e);
}
using :
try{
//some statements
} catch (Exception e) {
LOGGER.error(e);
}
Which one is better?
No comments:
Post a Comment