This is the mail archive of the cygwin mailing list for the Cygwin 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]

gcc 4.3.2 rethrow exception


Rethrowing an exception in Cygwin's gcc 4.3.2 causes an abort. This works
with gcc 3.4.4 and in Linux with gcc 4. Below is an example that is compiled
as: gcc rethrow.cpp -lstdc++.

Any insights would be appreciated.
-z

-----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>

void test2() throw(int)
{
	throw 2;
}

int rethrow_fail() throw(int)
{
	try
	{
		test2();
		return(0);
	}
	catch(int i)
	{
		throw; // this throw causes the program to abort
	}
}

int rethrow_ok() throw(int)
{
	int n;
	try
	{
		test2();
		return(0);
	}
	catch(int i)
	{
		n = i;
	}
	throw n; // this throw works since outside of the catch
}

int main()
{
	// -------------------------------------------------------
	// the following works with the exception caught
	// -------------------------------------------------------
	try
	{
		printf("rethrow_ok return=%d\n", rethrow_ok());
	}
	catch(int n)
	{
		printf("rethrow_ok exception=%d\n", n);
	}

	// -------------------------------------------------------
	// the following will fail with the program aborting when
	// build with Cygwin gcc 4.3.2
	// -------------------------------------------------------
	try
	{
		printf("rethrow_fail return=%d\n", rethrow_fail());
	}
	catch(int n)
	{
		printf("rethrow_fail exception=%d\n", n);
	}
	return(0);
}

// override of abort so can trap abort
extern "C" void abort(void)
{
	printf("abort\n");
	exit(1);
}
-----------------------------------------------------------------------
-- 
View this message in context: http://www.nabble.com/gcc-4.3.2-rethrow-exception-tp25645396p25645396.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


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