// try_fine.cpp too fine grain can cause problems // because 'try' is a statement, objects declared // in a 'try block' do not exists outside the block. #include class A { public: A(int i, int j) {ai=ii?j:i; if(i==j) throw "can't be equal"; } int geti(){ return ai;} int getj(){ return aj;} private: int ai; // smaller of pair int aj; }; int main() { A a(1,2); cout << a.geti() << endl; A b(2,1); cout << b.geti() << endl; try { A c(2,2); cout << c.geti() << endl; } catch(const char * s){ cout << "exception " << s << endl; } // cout << c.geti() << endl; 'c' not declared here return 0; }