Log And Rethrow Duplication (ARCH4166)
هذا المحتوى غير متوفر بلغتك بعد.
Key java.logging.log-and-rethrow · Severity warning · Category logging
Both logging and rethrowing an exception produces duplicate entries because it will be logged again higher up the stack. Either log or throw the exception, not both.
Incorrect
Section titled “Incorrect”try { repository.save(user);} catch (SQLException e) { log.error("Save failed", e); throw new DataAccessException(e);}Correct
Section titled “Correct”try { repository.save(user);} catch (SQLException e) { throw new DataAccessException("User save failed: " + user.id(), e);}If you rethrow, leave logging to the top boundary layer; do not both log and throw in the same place.