Throw exception in case there is a write error