Handle IO errors gracefully