Aller au contenu

Rethrow Loses Stack Trace (ARCH4154)

Ce contenu n’est pas encore disponible dans votre langue.

Key java.logging.rethrow-without-cause · Severity warning · Category logging

Throwing a new exception inside a handler without passing the original as the cause destroys the stack trace leading to the root cause. The true source of the error is lost and diagnosis becomes very hard.

try {
return repository.load(id);
} catch (SQLException e) {
throw new ServiceException("Load failed");
}
try {
return repository.load(id);
} catch (SQLException e) {
throw new ServiceException("Load failed", e);
}

Pass the original exception as the cause argument when constructing the new exception.