This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
c++ exceptions and signals
- To: egcs at egcs dot cygnus dot com
- Subject: c++ exceptions and signals
- From: Peter Maunz <pmaunz at eraser dot physik dot uni-konstanz dot de>
- Date: Mon, 11 Jan 1999 12:59:24 +0100 (MET)
- Reply-To: Peter Maunz <Peter dot Maunz at uni-konstanz dot de>
Hallo
I'm using egcs 1.1.1 on a SuSE 5.3 linux PII
and want to use signals (like SIGTERM)
by throwing an exception.
If I write a signalhandler and throw an exception there I don't manage to
catch this exception in the main program.
Do you know whats going wrong? Or how to make a signal throw an
exception and catch it?
Thanks a lot
The small program i tried:
#include <iostream.h>
#include <stdexcept>
#include <signal.h>
class Peter : public exception
{
public:
virtual const char* what () const { return "Peters Ausnahme"; }
};
void termhandler(int n)
{
signal(SIGTERM, termhandler );
cout << "Hier ist der Signalhandler"<<endl;
throw exception();
}
main()
try
{
cout << "Signal: " << signal(SIGTERM, termhandler ) << endl;
while(true)
sleep(15);
}
catch(exception& ex)
{
cout << "Caught exception : ";
cout << ex.what() << endl;
//throw;
}
catch(...)
{
cout << "Dies sollte alle exceptions abfangen." << endl;
throw;
}
Peter Maunz
University of Konstanz
Faculty of Physics
AG Prof Rempe
+49 7531 88-3838
Peter.Maunz@uni-konstanz.de