Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble with C++ exceptions rehashed



Hi,

I've upgraded to Appe's gcc3.3. The problem has gone away half-way; now, when the terminate_handler is in the same binary as the exception-generating throw clause, it works; but if it's in a separate shared library, it still loops.

I've written a small test program that loads a dylib containing a handler and throws an exception. If the program ("thrower") is called without any arguments, it uses the internal handler, which works; if it's called with any command line arguments, the empty throw clause at the beginning of the handler loops.

I've attached the code (two source files, header, Makefile). My problem is that the terminate_handler I want to use is precisely in a shared library, and I can't really change that. Is there any guru on this list who knows what's going wrong here?

Thanks in advance,
--Bjvrn

[ -- Makefile -- ]
all: libhandler.dylib thrower

CC=gcc

libhandler.dylib: handler.o
libtool -dynamic -o libhandler.dylib handler.o -lgcc -lstdc++ -lSystem

thrower: thrower.o
gcc -o thrower thrower.o -L. -lstdc++ -lhandler

clean:
rm -f *.o libhandler.dylib thrower *~

%.o: %.cc
$(CC) -c -o $@ $<

[ -- common.h -- ]
#include <stdlib.h>
#include <stdio.h>

class MyException {};
void myLibHandler(void);

[ -- thrower.cc -- ]
#include "common.h"
#include <exception>

void myHandler(void)
{
try {
printf("Re-throwing to determine type of exception\n");
throw;
} catch(MyException& exc) {
printf("MyException\n");
abort();
} catch(...) {
printf("Unknown exception\n");
abort();
}
}

int main(int argc, char **argv)
{
if(argc == 1)
{
printf("Using local handler\n");
std::set_terminate(myHandler);
}
else
{
printf("Using library handler\n");
std::set_terminate(myLibHandler);
}
printf("Throwing exception\n");
throw MyException();

return 0;
}

[ -- handler.cc -- ]
#include <stdio.h>
#include <stdlib.h>
#include "common.h"

void myLibHandler(void)
{
try {
printf("Re-throwing to determine type of exception\n");
throw;
} catch(MyException& exc) {
printf("MyException\n");
abort();
} catch(...) {
printf("Unknown exception\n");
abort();
}
}
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.