Build succeeds but program halts?


Ok, I’m not sure what’s going on here. I’ve checked my code and it matches what is in the book. When I build the program it succeeds without issues, however, when I run the program it halts on the line of code where we are generating the random number.

I get the message: Thread 1: Program received signal “EXC_ARITHMETIC”.

I’m not sure where to go from here. Help?


This is not nearly enough to go on. An EXC_ARITHMETIC is pretty rare – it usually comes from something like dividing by zero.

Post the code near where the program stops. (Especially any lines that do arithmetic.)


After looking at it again with a fresh pair of eyes, I realized that I had left out the line of code that adds the employee to the array. That’s what I get for trying to code after a long day. Anyway, all is working now. Thanks!


I am having the same issue, but I have all the code in place and am still getting this error (after the “///////” below)…

I am LOVING this book, but really hating myself right now because I know I’m doing something stupid and just don’t see it (I’ve concluded that since nobody else is reporting this issue). Can anyone see the error of my ways? Or do I need to post all code from all files?

  //create 10 assets
        for (int i=0; i < 10; i++) {
            //Create an asset
            Asset *asset = [[Asset alloc] init];

            //Give it an interesting label
            NSString *currentLabel = [NSString stringWithFormat:@"Laptop %d", i];
            [asset setLabel:currentLabel];
            [asset setResaleValue:i * 17];

            //Get a random number between 0 and 9 inclusive
            NSUInteger randomIndex = random() % [employees count];  /////////Thread 1: EXC_ARITHMETIC (code=EXC_1386_DIV, subcode=0x0)

            //Find that employee
            Employee *randomEmployee = [employees objectAtIndex:randomIndex];

            //Assign the asset to the employee
            [randomEmployee addAssetsObject:asset];


Your employee array is almost certainly empty or nil. Try logging it out right before the crash:

        NSLog(@"employees = %@", employees);
        NSUInteger randomIndex = random() % [employees count]; 

You might want to post the code where you alloc/init the array and where you fill it with employees via addObject:


Thanks so much for the reply. You were absolutely right. The employee array was empty and as I was pasting the full code per your request, I noticed that I had “i < 0” in my for loop, instead of “i < 10”. I looked over the code for 45 minutes and somehow missed that. :imp:


thanks !