#include <stdio.h> #include <string.h> #include <stdexcept> #include <signal.h> void throw_signal( int signum ) {// fprintf(stderr,"throw_signal: before throw; signum=%d\n",signum);fflush(stderr);
throw std::runtime_error ("throw_signal"); } int main() { struct sigaction new_action, d_old_action; memset (&new_action, 0, sizeof (new_action)); new_action.sa_handler = throw_signal; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; if (sigaction (SIGSEGV, &new_action, &d_old_action) < 0){ perror ("sigaction (install new)"); throw std::runtime_error ("sigaction"); } try { int j = *((int *)NULL); } catch (...){ printf("caught exception\n"); } }
g++ 3.3.4 gives the result I expect: $ sh /usr/bin/set-gcc-default-3.sh $ gcc --version gcc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -fnon-call-exceptions throw_segv.cc $ ./a.exe caught exception but g++ 4.3.4 aborts after the exception is thrown and before it is caught: $ sh /usr/bin/set-gcc-default-4.sh $ gcc --version gcc (GCC) 4.3.4 20090804 (release) 1 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -fnon-call-exceptions throw_segv.cc $ ./a.exe terminate called after throwing an instance of 'std::runtime_error' what(): throw_signal Aborted (core dumped)Am I misunderstanding how this should work or doing something wrong? Or is this a problem with Cygwin or gcc?
Thanks, -- Don W.
cygcheck.out
Description: Binary data
throw_segv.cc
Description: Binary data
-- 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