The pattern of catch wrap and re-throw and logging at every catch-point causes several entries in the log. What do you usually do ?
The pattern of catch wrap and re-throw and logging at every catch-point causes several
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Any individual exception should only be logged in 1 location to avoid clogging up your logs. As long as the exception contains the original cause, you should be able to trace back to it.
Personally I do the following:
Catch checked exception at lowest level point that I can, wrap in a RuntimeException (or subclass) with the best message to detail what was happening when the exception occurred and re-throw. No logging is done at the low level. Catch the unchecked (Runtime) exceptions at a very high level, just before it can impact a user. There it gets logged (with original cause) and converted into a useful message for the end user.
This only applies to exceptions that cannot be handled (which is most). There are other cases for things like connection retries, but I don’t think that’s the primary point of your question.