X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 	tests=BAYES_00,SPF_HELO_PASS,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <25645396.post@talk.nabble.com>
Date: Mon, 28 Sep 2009 07:38:40 -0700 (PDT)
From: zevel12 <zg.nab@zevelx.net>
To: cygwin@cygwin.com
Subject: gcc 4.3.2 rethrow exception
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com


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

