Refactoring exception catch