Added catch for writing error.