• 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
Clang & C++ exceptions in destructors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Clang & C++ exceptions in destructors


  • Subject: Clang & C++ exceptions in destructors
  • From: Jesper Papmehl-Dufay <email@hidden>
  • Date: Tue, 08 Jan 2013 11:27:49 +0100

It seems clang (or the “Apple LLVM Compiler”) doesn’t like it when I throw exceptions from a C++ destructor. Is this intentional, or should I report it as a bug?
(I aware that in general, throwing from a destructor is a very bad idea, I’m only doing it in very specific cases. For example, I know that my destructor is not called during stack unwinding due to another exception.)

For example, the following program will terminate with a “terminate called without an active exception” message when the destructor throws std::exception (testing using Xcode 4.5.2 on Mac OS X 10.7.5):


#include <stdexcept>

class CThrowInDestructor {
	public: CThrowInDestructor() {}
	public: ~CThrowInDestructor() {
		throw std::exception();
	}
};

int main(int argc, const char * argv[]) {
	CThrowInDestructor* instance = new CThrowInDestructor;
	try {
		delete instance;
		instance = NULL;
	}
	catch (...) {
	}
	return 0;
}


If I switch compiler to LLVM GCC 4.2, the program exits normally, so it seems the problem is specific to clang.


Thanks!
/Jesper

 _______________________________________________
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


  • Follow-Ups:
    • Re: Clang & C++ exceptions in destructors
      • From: Jean-Daniel Dupas <email@hidden>
  • Prev by Date: Re: Editor stops tabbing (apparently prefs-related)
  • Next by Date: Dependency on generated .h files in Xcode
  • Previous by thread: Re: Editor stops tabbing (apparently prefs-related)
  • Next by thread: Re: Clang & C++ exceptions in destructors
  • Index(es):
    • Date
    • Thread