Uncategorized

>Exceptional exception handling in C++

>#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.

Advertisements

Categories: Uncategorized

1 reply »

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.