Amazon.com Widgets Exercise 6
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 28, 2014, 09:36:58 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Answers to Exercises
| | |-+ Chapter 9
| | | |-+ Exercise 6
Pages: [1] Go Down
Print
Author Topic: Exercise 6 (Read 1243 times)
adamgonzalez1984
Jr. Member
**
Posts: 89






on: February 18, 2009, 11:59:06 AM

Is this right?


#import "Calculator.h"

int main (int argc, char *argv[])
{
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   Calculator *deskCalc;
   
   deskCalc = [[Calculator alloc] init];
   
   [deskCalc clear];
   [deskCalc setAccumulator:100.0];
   [deskCalc add: 200];
   @try {
      [deskCalc divide:15.0];
   }
   @catch (NSException *e) {
      NSLog(@"Caught %@", [e name]);
   }
   [deskCalc subtract:10.0];
   [deskCalc multiply:5];
   NSLog (@"The result is %g", [deskCalc accumulator]);
   [deskCalc release];
   
   [pool drain];
   return 0;
}

Logged
strells
Newbie
*
Posts: 8






Reply #1 on: May 04, 2009, 06:38:08 PM

Any idea why the errata says to delete this exercise (from the 1st printing, which I have)?

Steve
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #2 on: May 04, 2009, 06:48:05 PM

Division by zero will abort the program's execution but does not throw an exception.  In order to solve this problem, you need to test for division by zero in the code and then throw an exception yourself.  There's not enough details given in text on exception processing to show how to do that.   (next edition.  Grin )

Cheers,

Steve Kochan
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.