>#include
using namespace std;
//Global
int a = 20;
void foo()
try {
throw a;
}
catch(int &x)
{
// You can’t modify value of “a”
x = 10;
}
int main()
{
foo();
cout<<"A="<<a;
}
A=20 !!!!
When you write “throw a”, an invisible, phantom exception object gets created. You pass reference to that object and hence any change made to original object have no effect.
>Since it is the early worm that gets eaten by the bird, sleep late.............................................
LikeLike