This is the mail archive of the
mailing list for the GCC project.
Re: Unix Signals as OS Exceptions in C++
- From: Ian Lance Taylor <ian at wasabisystems dot com>
- To: "Steven T. Hatton" <hattons at globalsymmetry dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: 12 Sep 2004 10:15:20 -0400
- Subject: Re: Unix Signals as OS Exceptions in C++
- References: <email@example.com>
"Steven T. Hatton" <firstname.lastname@example.org> writes:
> The article on the following link discusses a mechanism to handle exceptions
> generated by the Microsoft Windows OS.
> Since the counterpart to the Windows Structured Exception Handling is
> (probably) Unix signaling, it seems a comperable mechanism on Unix and
> Unix-like OS's would need to translate signals to exceptions. This seems to
> me to be the domain of GCC.
> I've never heard of such a feature. Perhaps this is just a question of RTFM.
> If so, please let me know. If not, then let me suggest the gcj may provide
> an example of how to implement this support for C++ exception handling.
> Is this worth pursuing?
It already works fine; just call throw from your signal handler. This
programs works as expected on i386 GNU/Linux if you type ^C during the
void handler (int s)
struct sigaction s;
memset (&s, 0, sizeof s);
s.sa_handler = handler;
sigaction (SIGINT, &s, 0);
catch (int i)
std::cout << "Caught signal " << i << std::endl;
std::cout << "Didn't catch anything" << std::endl;