segmentation in unexpected_handler

Nick Godbey nick@sidi.com
Tue Jun 30 11:18:00 GMT 1998


I get a segmentation when overriding the unexpected_handler with
myh own. I wish to throw a known error object from my
unexpected_handler.

System RedHat Linux 5.0
egcs 1.0.2
binutils 2.8.1
glibc 2.0.6

gdb output

Program received signal SIGSEGV, Segmentation fault.
0x4006ad43 in memcpy (dstpp=0xbfffb2b0, srcpp=0xbfffb2c8, len=4)
    at ../sysdeps/generic/memcpy.c:57
../sysdeps/generic/memcpy.c:57: No such file or directory.
Current language:  auto; currently c


Program:

#include <iostream.h>

class TestErr
{
public:
 TestErr()
  : i(1)
  {}
 ~TestErr() {}
 int i;
};

class TestWarning
{
public:
 TestWarning()
  : i(2)
  {}
 ~TestWarning() {}
 int i;
};


void throw_func();
void test_func()   throw ( TestErr );


// replace unexpected handler with our own.
typedef void(*PFV)();

PFV set_unexpected(PFV);

void our_unexpected_handler();


void  our_unexpected_handler ()
{
     throw TestErr();
}

void throw_func()
{
     throw TestWarning();
}

void test_func()   throw ( TestErr )
{
     throw_func();
}

int main(int argc, char* agrv[])
{

 set_unexpected( our_unexpected_handler );

     try
     {
          test_func();
     }
     catch( TestErr err)
     {
          cout << "caught TestErr\n";
     }

     return 0;
}





More information about the Gcc-bugs mailing list