Amazon.com Widgets Programs 9.4 and 9.5
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2013, 07:25:15 AM
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
|-+  Programming in Objective-C, 4th edition
| |-+  Chapter 9
| | |-+  Programs 9.4 and 9.5
Pages: [1]   Go Down
Print
Author Topic: Programs 9.4 and 9.5  (Read 664 times)
plantboy
Newbie
*
Posts: 6






« on: June 30, 2012, 01:40:39 PM »

Hello,

Here is my code for program 9.4, copied from the book:
Code: (Objective-C)
int main (int argc, const char * argv[])
{

    @autoreleasepool {
      
        Fraction *f = [[Fraction alloc] init];
        [f noSuchMethod];
        NSLog(@"Execution continues!");

    }
    return 0;
}

I am unfortunately not able to re-create the error, because XCode will not run the job. Please see the attached screenshot. (The entire point to this exercise is to submit the job and to see the error during runtime.)

I have a similar problem with program 9.5.

Thanks!

Logged
plantboy
Newbie
*
Posts: 6






« Reply #1 on: July 09, 2012, 07:55:13 PM »

I think I found the answer over here:
http://classroomm.com/objective-c/index.php?action=printpage;topic=6265.0
Logged
kritchens
Newbie
*
Posts: 10






« Reply #2 on: October 04, 2012, 06:36:10 PM »

yea it didnt work for me either, you can however see this in action if you do the following :

add the Fraction.h and Complex.h files,

Set them to the ID dataValue Variable

and while dataValue is now actually a Complex Object attempt to call the SetTo:SetOver: Method for fraction and you will get the error. This teaches a couple things such as how careful you have to be when using the ID variable type and how the Exceptions work. Try it out!

Code: (Objective-C)
#import <Foundation/Foundation.h>
#import "Fraction.h"
#include "Complex.h"
   
    int main(int argc, const char * argv[])
    {
       
        @autoreleasepool {
           
            id dataValue;
            Fraction *f1 = [[Fraction alloc]init];
            Complex  *c1 = [[Complex alloc]init];
           
           
            [f1 setTo:2 over:5];
            [c1 setReal:10.32 setImaginary:2.5];
           
            dataValue = f1;
            dataValue = c1;
            @try {
                [dataValue setTo:5 over:6];
            }
            @catch (NSException *exception) {
                NSLog(@"Caught %@%@",[exception name],[exception reason]);
            }
            NSLog(@"Execution Continues");
           
           
           
           
           
        }
        return 0;
    }

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.