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

Re: Clang & C++ exceptions in destructors


  • Subject: Re: Clang & C++ exceptions in destructors
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Tue, 08 Jan 2013 12:01:37 +0100

Le 8 janv. 2013 à 11:27, Jesper Papmehl-Dufay <email@hidden> a écrit :

> 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.


What version of Xcode are you using ? With Xcode 4.5.2, it behaves as expected.
I added a print statement in the catch clause in your sample, and it is properly printed before the program exits normally.

-- Jean-Daniel





 _______________________________________________
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


References: 
 >Clang & C++ exceptions in destructors (From: Jesper Papmehl-Dufay <email@hidden>)

  • Prev by Date: Dependency on generated .h files in Xcode
  • Next by Date: Re: Clang & C++ exceptions in destructors
  • Previous by thread: Clang & C++ exceptions in destructors
  • Next by thread: Re: Clang & C++ exceptions in destructors
  • Index(es):
    • Date
    • Thread