error handling on opening files