error handling during writing