catch io exceptions when flushing buffer too