error handling the write