Should I frequently use try catch blocks and how do I determine when and where I need them the most? Also what should do with the exception when it gets caught as a normal practice on small to medium scale departmental business applications? Also is there a free tool to help me locate duplicate code or code that would be ideal to refactor up the food chain? I’ve got ReSharper and it’s great but I need something to help me analyze what needs to be refactored.
Thanks.
Try..catch blocks should only be used when you can fix the error, are catching in order to perform cleanup before rethrowing (i.e. database rollback), or in a top level catch to log the exception before crashing.
You should never silently swallow exceptions – from that point on your application may be in an inconsistent state and you can’t trust it. Best to crash hard with logging information. Consider using Microsoft’s crash reporting service as well for debugging and statistical purposes.