try
{
object = mayThrow();
}
catch (const std::exception& exc)
{
//...
}
If mayThrow() actually throws, will the original object be untouched? Or is it better to do it this way?
try
{
Object newObject = mayThrow();
object = std::move(newObject);
}
catch (const std::exception& exc)
{
//...
}
Unless
mayThrow()has direct access toobjectand does some monkeying within, the final assignment happens if and only ifmayThrow()returns successfully and the object stays unchanged otherwise.