Catching C++ exceptions thrown from a framework
Catching C++ exceptions thrown from a framework
- Subject: Catching C++ exceptions thrown from a framework
- From: "Stuart A. Malone" <email@hidden>
- Date: Fri, 14 Jul 2006 11:29:20 -0400
We've just run into a subtle problem with a C++ application we've
ported from CodeWarrior to Xcode. We're finding that C++ exceptions
thrown by our framework cannot be caught by our main application as
specific types, only as generic ones.
Some background: In order to support a main application, a
background application and a Spotlight importer, we've placed much of
our common code into a private framework that's stored in our
application bundle. This framework is built as a target in the same
Xcode project that we use for building the applications and the
importer, so we know that all of the targets are in sync and we don't
have to worry about versioning issues as our C++ interfaces change.
To demonstrate the problem, we've created a simple test project
(which I can provide if anyone is interested). Consider the
following files:
FindAction.h:
#include <exception>
class NotFound: public std::exception {
};
void Find();
FindAction.cpp:
void Find() {
throw NotFound();
}
Test.cpp:
#include "FindAction.h"
#include <stdio.h>
void Test() {
try {
Find();
}
catch (NotFound & err) {
printf("good\n");
}
catch (...) {
printf("bad\n");
}
}
If both Test.cpp and FindAction.cpp are linked into the main
application, then the test prints "good", but if FindAction.cpp is
moved into the framework, then it prints "bad".
I guess we have two questions:
- Are other folks agreed that this is some kind of bug in Xcode/gcc/
linker, and not a subtle boundary case in the C++ specification that
we've stepped outside of?
- Does anyone know of a workaround (minor code changes, Xcode
settings) that would get this to work without having to restructure
our project in major ways? Because of other dependencies in the
code, it's not so easy for us to move the file that's throwing the
exception out of the framework and into the main app.
Best wishes,
--Stuart A. Malone
Llamagraphics, Inc.
Makers of Life Balance personal coaching software
http://www.llamagraphics.com/
_______________________________________________
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