Check return code of write