I am new to java and I have given to fix these violations. Can any one let me the fix for this Preserve stack trace. I should be passing the original exception but in this code, how to fix it. Thanks for your time
Thanks Campbell for purging the spaces. At line 17, my SONAR compiler complains "Preserve Stack trace violation". Generally, for other types of code for Preserve stack trace, I have passed the exception cause in the constructor. But here, we got two catch blocks, if inner catch block executes, then possibly original stack trace might be lost from first catch block.
Well, chaining both exceptions to a new exception (or to each other) could be tough. You could try it with initCause(), but depending on how the original exception was created, that may not work.
I tend to think that Sonar/Findbugs are full of crap here. You've logged each exception; that should be enough as far as preserving information is concerned. If you also want to throw a new exception and include the cause, great - but personally I would consider the original exception more important than the subsequent exception. That's your call though. Either way, FindBugs is simply wrong here. So the best solution is to disable it.
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad: