Catch possible errors when handling files