0

I have the following piece of code in my program and I am running SonarQube for code quality check on it after integrating it with Maven.

However, Sonar is complaining that I should Either log or rethrow this exception.

What am I missing here? Am I not already logging the exception?

public AccountResponse  getAccountStatus(AccessIDSearchResponse accessIDResponse) {
    accountResponse = null;
    try {
        AccountRequest request = new AccountRequest();
    } catch (ServiceException serviceException) {
        log.error("getAccountStatus-GotServiceException =" + ExceptionUtils.getStackTrace(serviceException));
        throw serviceException;
    } catch (Exception e) {
        throw new ServiceException(ErrorMessages.EPO_SYSTEM_ERROR, e.getMessage());
    }
    return accountResponse;
}

enter image description here

Krish
  • 4,166
  • 11
  • 58
  • 110
  • Can some one suggest me? – Krish May 29 '20 at 11:53
  • You should either handle the exception by yourself (logging) or rethrow it. But you do both. If you rethrow the exception you shouldn't log because someone else should decide what to do. – vanje May 29 '20 at 11:57
  • catch (ServiceException serviceException) { log.error("getAccountStatus-GotServiceException =" + ExceptionUtils.getStackTrace(serviceException)); throw serviceException; } – Krish May 29 '20 at 11:58
  • you mean in ServiceException have to Remove logger? – Krish May 29 '20 at 11:59

0 Answers0