• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Catching C++ exceptions thrown from a framework
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Prev by Date: Re: Enabling NSZombieEnabled depending on build configuration.
  • Next by Date: Re: Xcode flags to gcc
  • Previous by thread: Re: Enabling NSZombieEnabled depending on build configuration.
  • Next by thread: Re: Catching C++ exceptions thrown from a framework
  • Index(es):
    • Date
    • Thread