public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Nonterminating exceptions with longjump?
@ 2003-02-02 23:07 Gabor Greif
  2003-02-03 13:20 ` Andrew Haley
  0 siblings, 1 reply; 3+ messages in thread
From: Gabor Greif @ 2003-02-02 23:07 UTC (permalink / raw)
  To: gcc

I have a crazy idea for a long time but I did not dare to
articulate it till now. I know it is not standard-conformant,
but I just want to know whether it would work with g++.

I intend to simulate non-terminating exceptions on top of the
g++ exception handling machinery (sjlj-based or
table based, whatever). The call stack won't
contain destructors, just exception handlers.

consider this (untested, pseudocode):

struct non_terminate
{
	jmp_buf resume;
};

// demonstrate throw
//
void bar(void)
{
	non_terminate exc;
	if (setjmp(exc.resume))
	{
		// do I need to call some library
		// function to end the throw?
//		__exception_complete(); // or such...

		// report it
		cout << "resuming execution" << endl;


		cout << "throwing again" << endl;
		throw exc;
	}
	else
	{
		cout << "throwing exception" << endl;
		throw exc;
	}
}

// demonstrate handler
//
void foo(void)
{
	try {
		bar();
	} catch (non_terminate& resumer)
	{
		cout << "handling exception" << endl;
		throw;
	}
}


// main routine
void thread_entry(void)
{
	try {
		foo();
	} catch (non_terminate& resumer)
	{
		cout << "resuming to thrower" << endl;
		longjmp(resumer.resume,1);
	} catch (...)
	{
		cout << "huh?" << endl;
	}
}

I understand that in order for this to work, the stack
unwinding must happen after all handlers are done
and there must be a callable function like
__exception_complete that "unhappens" the exception
but does not cut the stack. This is needed in order to
avoid "terminate" because of an exception thrown
while unwinding.

I am interested to know whether there is any chance that
this scheme does work (and keeps working in forseeable
future) with g++.

Thanks for your patience.

	Gabor

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-02-04  1:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-02 23:07 Nonterminating exceptions with longjump? Gabor Greif
2003-02-03 13:20 ` Andrew Haley
2003-02-04  1:16   ` Gabor Greif

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).