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
I have removed the excess spaces and line numbers from your code; both make it harder to read. Please explain the problem a bit more.
Joined: Sep 21, 2012
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.
Joined: Oct 13, 2005
Don’t know about SONAR. Anybody else?
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com