This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: g++: Exception handling in constructor


This is not throwing that exception, it seems like a bug in the g++
parser;


#include <iostream>

using std::cout;
using std::cerr;
using std::endl;

struct Exception { };

class Bad {
public:
    Bad() {}
    Bad(int) { cout<<"Throwing Exception..."<<endl; throw Exception(); }
};

class Test {
    Bad b;
public:

    Test()
    {
	try
	{
	    b = Bad(0);
	    cout<<"Test"<<endl;
	}
	catch(Exception)
	{
	    cerr<<"Caught Exception -- this is right"<<endl;
	}
    }
};

int main()
{
    try {
	Test t;
    } catch(Exception) {
	cerr<<"Caught Exception -- should not happen"<<endl;
    }
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]