[ create a new paste ] login | about

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

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


class A 
{ 
public: 
    A() { cout << "A's Ctor" << endl; } 
    A(const A&) { cout << "A's Copy 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
8
9
Bs ctor
A's Ctor
A's Copy Ctor
A's Dtor
B dtor
A's Copy Ctor
Exception in A
A's Dtor
A's Dtor


Create a new paste based on this one


Comments: