c++ exceptions and signals

Peter Maunz pmaunz@eraser.physik.uni-konstanz.de
Sun Jan 31 23:58:00 GMT 1999


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



More information about the Gcc mailing list