• 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
Objective-C++ Exceptions (was: PICT control problems)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Objective-C++ Exceptions (was: PICT control problems)


  • Subject: Objective-C++ Exceptions (was: PICT control problems)
  • From: Steve Sisak <email@hidden>
  • Date: Sat, 24 Jun 2006 12:22:38 -0400

On Jun 24, 2006, at 10:36 AM, Marshall Clow wrote:
At 10:28 AM -0500 6/24/06, Bill Bumgarner wrote:
Objective-C is trivial to learn for a C programmer. And you can use C++ in Objective-C apps just fine.

[ For the non-metaphorically minded - Objective C and C++ have different exception models, and they don't play well together at all ]

If your own code throws NSExceptions as a part of execution to indicate user error, then your architecture is fighting against the grain of Cocoa and I would suggest that <...> you reconsider the architecture of your app.

Let me make Marshall's point al little clearer for you:

Objective-C exceptions don't call the destructors of stack based objects as the stack unwinds.

C++ exceptions don't respect Objective-C's conventions either.

Also, there's lots of people here who write things that aren't applications or who use 3rd party libraries or extant open source code that already have an existing model.

Given bindings, KVO, KVC and other Cocoa centric mechanisms, the most effective integration of C++ in Cocoa that I have encountered generally involves wrapping the C++ objects in Objective-C objects such that the full extent of the Cocoa framework(s) can be leveraged to build the UI. This naturally leads to a well defined line across which exception handling can be divided.

And you've just shot yourself in the head when (for instance) the destructor of a C++ smart pointer isn't called.


This is the point Marshall was trying to make.

Setting reply-to to cocoa-dev because this has now gone well beyond the charter of xcode-users.

This isn't a Cocoa issue in any way, shape, or form -- it's a compiler/language runtime issue. Not sure of the correct list, but this is way closer than cocoa-dev.


Since Apple has defined the new language "Objective-C++" that language's exception mechanism needs to interoperate with both of the existing languages models.

This was glossed over because it's hard to do w/o potentially breaking existing code.

Currently, Objective-C just uses setjmp/longjmp -- I don't see any reason that Objective-C++ couldn't throw a special C++ exception instead (which would insure that destructors are called and could even be caught from C++).

And I'm not saying it's easy to implement w/o breaking existing code -- but it is necessary or mixing C++ and Objective-C will continue to be very dangerous in subtle ways.

-Steve
_______________________________________________
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: Objective-C++ Exceptions (was: PICT control problems)
      • From: Bill Bumgarner <email@hidden>
References: 
 >PICT control problems (From: John Lunt <email@hidden>)
 >Re: PICT control problems [SOLVED] (From: John Lunt <email@hidden>)
 >Re: PICT control problems [SOLVED] (From: Scott Thompson <email@hidden>)
 >Re: PICT control problems [SOLVED] (From: John Lunt <email@hidden>)
 >Re: PICT control problems [SOLVED] (From: Markus Hitter <email@hidden>)
 >Re: PICT control problems [SOLVED] (From: John Lunt <email@hidden>)
 >Re: PICT control problems [SOLVED] (From: Bill Bumgarner <email@hidden>)
 >Re: PICT control problems [SOLVED] (From: Marshall Clow <email@hidden>)
 >Re: PICT control problems [SOLVED] (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: PICT control problems [SOLVED]
  • Next by Date: can I catch an EXC_BAD_ACCESS?
  • Previous by thread: Re: PICT control problems [SOLVED]
  • Next by thread: Re: Objective-C++ Exceptions (was: PICT control problems)
  • Index(es):
    • Date
    • Thread