But in your pattern, you will still print multiple stack traces because when you pass SomeOtherException to log.error further up the stack, you will see its stack trace plus the stack trace of the original exception. Providing some meaningful info, maybe about what method threw the Exception is a great practice to follow, but that's what the message parameter to the wrapping exception is for. Why do the same thing twice? Just look at your code; you have copy/pasted "I got exception" and e.getMessage() all in the span of 2 lines. That should clue you into the fact that something is not right there.
Your example also brings up another antipattern that I didn't mention in the article (2 antipatterns in one example, nice job. :) There is no reason to append e.getMessage() to the message parameter when you're creating SomeOtherException. The message is contained in the wrapped exception, and logging the wrapped exception will still produce the original exception message, along with the original stack trace. There's no good reason for the user to have to see it twice. |