Iqbal Haider
Iqbal Haider

Reputation: 310

Stream operator exception in C++ is unrollback able

String EvaluateSalaryAnadReturnName( Employee e) {
    if (e.Title() == "CEO" || e.Salary() > 10000) {
        cout << e.First() << " " << e.Last() << " is overpaid" << endl;
    }

    return e.First() + " " + e.Last();
}

In above program I studied that if Exception generated in cout at << is overpaid or any cout stream the strong guarantee says that if the function fails because of enter code here an exception, the program state must not be changed.

stream operators (<<) in C++ is not roll able when Exception is generated due to it. Means when exception is generated due to << operator

So due to unroll able or not full commit or not complete roll back its state is to be changed

Can anybody explain me why it is not rollback able

Upvotes: 0

Views: 98

Answers (1)

user1804599
user1804599

Reputation:

Some data may already been written to an output device, but you cannot tell that output device to somehow undo it. Think about it, if you pipe your output to a speech synthesis program, should it travel back in time to undo the audio output? How about a printer?

Rolling back is not possible when you don’t know where the output will go.

Prefer not to mix I/O and business logic, since I/O is likely to fail due to external factors being involved (other processes and hardware).

Upvotes: 3

Related Questions