I currently have some code I am trying to refactor. A large set of exceptions has some common code for all exceptions as well as some specific code which needs to be handled
A large set of exceptions has some common code
Move the common code into a function or method. Call the method from each catch
. Just like eliminating any other duplication; the presence of a try
..catch
makes no difference.
But if you are really concerned about "a large set of exceptions", the real problem might be that you have a large set of exceptions. Why do different exceptions require different handling at all? Are exceptions really being used for only exceptional events?