• 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: My try/catch block isn't catching exceptions on 10.6
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: My try/catch block isn't catching exceptions on 10.6


  • Subject: Re: My try/catch block isn't catching exceptions on 10.6
  • From: Kai Brüning <email@hidden>
  • Date: Mon, 30 Nov 2009 09:09:26 +0100

On 28.11.2009, at 13:57, Gwynne Raskind wrote:

> On Nov 28, 2009, at 4:25 AM, Greg Parker wrote:
>> Here's a fun idiom for handling both C++ and Objective-C exceptions in the same place (on iPhone and 64-bit Mac).
>>
>>   @try {
>>       // do stuff
>>   } @catch (NSException *e) {
>>       // NSException
>>   } @catch (id e) {
>>       // Other Objective-C exception
>>   } @catch (...) {
>>       // Non-ObjC exception
>>       // Decode it by rethrowing it inside a C++ try/catch.
>>       try {
>>           @throw;
>>       } catch (std::bad_cast& e) {
>>           // C++ failed dynamic cast to reference type
>>       } catch (...) {
>>           // Other C++ exception
>>           // or non-ObjC non-C++ foreign exception
>>       }
>>   }
>
>
> I apologize if this is a dense question, but can't you just go like this?
>
>   @try {
>       // do stuff
>   } @catch (NSException *e) {
>       // NSException
>   } @catch (id e) {
>       // Other Objective-C exception
>   } @catch (std::bad_cast& e) {
>       // C++ failed dynamic cast to reference type
>   } @catch (...) {
>       // Other C++ exception
>       // or non-ObjC non-C++ foreign exception
>   }

No - there’s a syntactically subtle but important difference above between @try/@catch and try/catch, the further being the Objective-C variant, the later C++.

Kai

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >My try/catch block isn't catching exceptions on 10.6 (From: Mark Allan <email@hidden>)
 >Re: My try/catch block isn't catching exceptions on 10.6 (From: Graham Cox <email@hidden>)
 >Re: My try/catch block isn't catching exceptions on 10.6 (From: Matt Gough <email@hidden>)
 >Re: My try/catch block isn't catching exceptions on 10.6 (From: Greg Parker <email@hidden>)
 >Re: My try/catch block isn't catching exceptions on 10.6 (From: Gwynne Raskind <email@hidden>)

  • Prev by Date: Re: Core Data and +[NSExpression expressionForFunction:...]
  • Next by Date: Re: troubles with tableview
  • Previous by thread: Re: My try/catch block isn't catching exceptions on 10.6
  • Next by thread: Re: My try/catch block isn't catching exceptions on 10.6
  • Index(es):
    • Date
    • Thread