Example

int funct(){
int exception = 2;
if(exception){
throw exception;
}
return 0;
}

int main()
{
try {
funct();
}
catch (int ex) {
cout << ex;
}
   
return 0;
}

Solution
Catch a reference to the exception.

int funct(){
int exception = 2;
if(exception){
throw exception;
}
return 0;
}

int main()
{
try {
funct();
}
catch (int &ex) {
cout << ex;
}
   
return 0;
}