Error handling in text file