Throw exception vs Logging
10:58 27 Feb 2014

Is the following way to code good practice?

try {
    //my code here
} catch (Exception e) {
    logger.error("Some error ", e);
    throw new MyCustomException("Some error ", e);
}

Moreover, should I..

  • use only the logger?
  • throw only the exception?
  • do both?

I understand that with throw I can catch the exception in another part of the callstack, but maybe additional logging has some hidden benefits and is useful as well.

best-practices java exception logging try-catch