I am interested to know if is it correct to move an exception object to some local variable. Is there any possibility for this action to lead into UB? My concerrns are due to the fact that catching by reference assumes access to exception object, which is located in other place (because it must live until the end of the stack unwinding). See example below.
int main()
{
std::pair<int,int> res; //may be heavy object, it's only example
int a[3][5];// assume filled
try
{
for(int i = 0; i < 3; ++i)
{
for(int j = 0; j < 5; ++j)
{
if(a[i][j] % 2 ==0 )
{
throw std::pair<int,int>(i,j);
}
}
}
}catch(std::pair<int,int>& pair)
{
res = std::move(pair);
}
}