Re: Under what circumstances will catch (...) not catch?
Re: Under what circumstances will catch (...) not catch?
- Subject: Re: Under what circumstances will catch (...) not catch?
- From: Larry Campbell <email@hidden>
- Date: Fri, 30 Nov 2007 15:27:31 -0500
On Nov 28, 2007, at 6:29 PM, Larry Campbell wrote:
On Nov 28, 2007, at 6:25 PM, David Rowland wrote:
On Nov 28, 2007, at 3:16 PM, Larry Campbell wrote:
In a large project that worked well under Tiger and Xcode 2.4, I'm
having a bizarre problem with Leopard and Xcode 3.0. In the
following snippet:
bool failed = false;
try {
minfo.read(instr);
} catch (...) {
failed = true;
}
minfo.read() is expected to throw an exception, and it does, but
the runtime acts as though there's no handler in scope and calls
abort(), rather than letting my handler run.
How can this be?
any chance that some destructor which is called for a local var is
also throwing an exception?
Don't think so -- the debugger shows that the exception resulting in
a call to abort is the exception I expected to be thrown.
I narrowed this down to a small reproducible test case. It seems to be
a PPC-specific bug in gcc. On Intel-based Macs the code works. I've
opened radar #5620736.
Since the code is small and this might be of general interest, I'll
paste it here. The makefile builds seven variants of the program. Two
fail (on PPC/Leopard/Xcode 3.0) and five work. They all work on Intel-
based Macs running either Leopard/Xcode 3.0 or Tiger/Xcode 2.4. (They
also all work on linux/x86 with gcc 3.3 and gcc 4.1.)
- lc
Foo.h:
======
#ifndef FOO_H
#define FOO_H
#include <cstdio>
struct Exception {
};
void throwError(const char* fmt, ...);
#ifndef NO_INLINING
inline void throwError(const char* fmt, ...)
{
Exception exc; // even though this is not used, removing it
makes the test work!
printf("Throwing exception\n");
throw "foo";
}
#else
void throwError(const char* fmt, ...);
#endif
#endif // FOO_H
Foo.cc:
=======
#include <cstdio>
#include "Foo.h"
#ifdef NO_INLINING
void throwError(const char* fmt, ...)
{
Exception exc;
printf("Throwing exception\n");
throw exc;
}
#endif
// function is not called but must be present to reproduce bug
void foo()
{
throwError("foo");
}
Bar.cc:
=======
#include <cstdio>
#include "Foo.h"
static void throwSomething()
{
throwError("foo");
}
int main()
{
try {
throwSomething();
printf("error: exception not thrown\n");
} catch(...) {
printf("ok: exception was caught\n");
}
printf("test ok\n");
return 0;
}
Makefile
========
PROGS = Bar.fail1 Bar.fail2 Bar.ok1 Bar.ok2 Bar.ok3 Bar.ok4 Bar.ok5
all: $(PROGS)
-./Bar.fail1
-./Bar.fail2
./Bar.ok1
./Bar.ok2
./Bar.ok3
./Bar.ok4
./Bar.ok5
# this fails
Bar.fail1: Foo.cc Bar.cc
g++ -O3 -c Foo.cc -o Foo.o
g++ -c Bar.cc -o Bar.o
g++ -o $@ Bar.o Foo.o
# -O2 instead of -O3 also fails
Bar.fail2: Foo.cc Bar.cc
g++ -O2 -c Foo.cc -o Foo.o
g++ -c Bar.cc -o Bar.o
g++ -o $@ Bar.o Foo.o
# reversing the link order works
Bar.ok1: Foo.o Bar.o
g++ -O3 -c Foo.cc -o Foo.o
g++ -c Bar.cc -o Bar.o
g++ -o $@ Foo.o Bar.o
# no -O3 for Foo.cc works
Bar.ok2: Foo.o Bar.o
g++ -c Foo.cc -o Foo.o
g++ -c Bar.cc -o Bar.o
g++ -o $@ Bar.o Foo.o
# -O3 for both works
Bar.ok3: Foo.o Bar.o
g++ -O3 -c Foo.cc -o Foo.o
g++ -O3 -c Bar.cc -o Bar.o
g++ -o $@ Bar.o Foo.o
# disabling inlining works
Bar.ok4: Foo.cc Bar.cc
g++ -DNO_INLINING -O3 -c Foo.cc -o Foo.o
g++ -DNO_INLINING -c Bar.cc -o Bar.o
g++ -o $@ Bar.o Foo.o
# -O1 instead of -O3 works
Bar.ok5: Foo.cc Bar.cc
g++ -O1 -c Foo.cc -o Foo.o
g++ -c Bar.cc -o Bar.o
g++ -o $@ Bar.o Foo.o
clean:
rm -f *.o *~ $(PROGS)
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden