[ create a new paste ] login | about

Link: http://codepad.org/9k6nZPVw    [ raw code | output | fork ]

C++, pasted on Feb 26:
 #include <iostream> 
using namespace std; 


class A 
{ 
public: 
    A() { cout << "A's Ctor" << endl; } 
    ~A() { cout << "A's Dtor" << endl; } 
    const char *what() const { return "Exception in A"; } 
}; 
class B 
{ 
public: 
    B() { cout << "Bs ctor" << endl; } 
    ~B() { cout << "B dtor" << endl; } 
}; 

void MyFunc() 
{ 
    B b; 
    throw A(); 
} 

int main() 
{ 
    try 
    { 
        MyFunc(); 
    } 
    catch (A a) 
    { 
        cout << a.what() << endl; 
    } 
    catch (char *str) 
    { 
        cout << "Caught some other ex " << str << endl; 
    } 
}  


Output:
1
2
3
4
5
6
7
Bs ctor
A's Ctor
A's Dtor
B dtor
Exception in A
A's Dtor
A's Dtor


Create a new paste based on this one


Comments: