Try catch refactoring for IO