Refactoring try-catch blocks