This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Throwing C++ exceptions from signal handlers

is it possible to somehow convince gcc to properly throw an exception from a
signal handler context?
I saw the discussion of 2 years ago in this mailing list,, and though it didn't raise
my hopes it does claim that in some cases this is being done.  How exactly?
Can it only be done for very special cases, or is there some setup that will
allow me to throw any exception from inside any signal handler?

In particular, I'd like to get the following program to run on Linux with
gcc.  On Solaris (with Sun's compiler) it works fine.
#include <stdio.h>
#include <signal.h>
#include <string.h>

void sigpipeHandler(int x)
    signal(SIGPIPE, sigpipeHandler);  //reset the signal handler
    fprintf(stderr,"throw: %s\n",strsignal(x));
    throw strsignal(x);  //throw the exeption

int main(int argc, char *argv[])
    int x;

    signal(SIGPIPE, sigpipeHandler);
    { raise(SIGPIPE); }
    catch(const char *except)
    { fprintf(stderr,"catch: %s\n",except); }
    { fprintf(stderr,"Exception\n");  }

    return 0;


Much obliged for any help,
- Yuval
Yuval Kfir, Kernel team leader
Mainsoft Corporation

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]