From: Gabor Greif <gabor@mac.com>
To: gcc@gcc.gnu.org
Subject: Nonterminating exceptions with longjump?
Date: Sun, 02 Feb 2003 23:07:00 -0000 [thread overview]
Message-ID: <B8A346E4-36FF-11D7-B1B2-000393A34C6C@mac.com> (raw)
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
next reply other threads:[~2003-02-02 23:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-02 23:07 Gabor Greif [this message]
2003-02-03 13:20 ` Andrew Haley
2003-02-04 1:16 ` Gabor Greif
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=B8A346E4-36FF-11D7-B1B2-000393A34C6C@mac.com \
--to=gabor@mac.com \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).