Handle write and read errors.