Lets consider I have the following function:
SomeType createSomeType();
which can throw depending on some reasons.
Then:
SomeType val = SomeType(); // initial value
try
{
val = createSomeType(); // here
}
catch (std::exception&)
{
}
If createSomeType() throws, can I always assume that val value is unchanged ?
Yes, if createSomeType() throws an exception, the assignment will not happen. The flow of control will go from the throw statement, through the destructors of any objects createSomeType() has on the stack and finally to the catch statement.