LHS state after exception is thrown

I am studying exceptions in C ++, and I would like to clarify the scenario:

T function() throw(std::exception);
...
T t = value;
try { t = function(); }
catch (...) {}

if an exception is thrown, what is the state of the variable t? unchanged or undefined?

+3
source share
3 answers

Without changes. tcannot be assigned until function()it returns a value, but function()never returns normally

+3
source

It's not so easy. The catch clause will also take into account the exceptions thrown by the assignment operator for the object class t. Object t may be partially assigned. Never catch all the exceptions and assume that the most probable happened.

+6
source

t , . t, .

+3

Source: https://habr.com/ru/post/1741622/


All Articles