refactoring try/catch block