• 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: try/catch/throw/finally example?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: try/catch/throw/finally example?


  • Subject: Re: try/catch/throw/finally example?
  • From: Roland Silver <email@hidden>
  • Date: Sat, 26 Aug 2006 05:31:47 -0600

Todd,
I can follow your example, except for the last paragraph, where you say:
You also need to enable these options in your build settings.
In Xcode, check the "Enable Objective-C Exceptions" box in your target's build settings.

Where are the target's build settings, in which the "Enable Objective- C Exceptions" box appears?


I tried double-clicking Groups & Files > Targets > UObjectDebug, and selecting the "Build" tab,
but that doesn't seem to be it.
------------------------------------------------------
On Aug 25, 2006, at 1:06 PM, Todd Yandell wrote:



On Aug 25, 2006, at 12:38 PM, Roland Silver wrote:

Can someone suggest a tutorial or example of the use of @try, @catch, @throw, @finally, in Objective-C, other than the Apple document "Exception Handling and Thread Synchronization"?

NSString *stringOne = @"One"; NSString *stringTwo = @"Two";

@try {
   [stringOne appendString:stringTwo];
} @catch (id theException) {
   NSLog(@"%@ doesn't respond to appendString:!", [stringOne class]);
} @finally {
   NSLog(@"This always happens.");
}

@throw [NSException exceptionWithName:@"Test"
   reason:@"Testing the @throw directive." userInfo:nil];

In the "@catch" block, "theException" will point to an NSException that describes the exception that was caught. The "@finally" block will always be executed, whether an exception was thrown or not. Normally you would use "@finally" to clean up any objects you created in the try "@try" block.

The "@throw" directive does the same thing as "[myException throw]".

You also need to enable these options in your build settings. In Xcode, check the "Enable Objective-C Exceptions" box in your target's build settings. With GCC, you need to use the "-fobjc- exceptions" flag.

Todd


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: try/catch/throw/finally example?
      • From: Chris Hanson <email@hidden>
References: 
 >try/catch/throw/finally example? (From: Roland Silver <email@hidden>)
 >Re: try/catch/throw/finally example? (From: Todd Yandell <email@hidden>)

  • Prev by Date: Where did I just type that character?
  • Next by Date: NSSavePanel, NSOpenPanel... Where is NSChoosePanel?
  • Previous by thread: Re: try/catch/throw/finally example?
  • Next by thread: Re: try/catch/throw/finally example?
  • Index(es):
    • Date
    • Thread