An integer divide-by-zero operation is fatal on an x86 system but the operation continues on a PowerPC system, where it returns zero. (A floating point divide-by-zero behaves the same on both architectures.) If you get a crash log that mentions EXC_I386_DIV (divide by zero), your program divided by zero. Mod operations perform a divide, so a mod-by-zero operation produces a divide-by-zero exception. To fix a divide-by-zero exception, find the place in your program corresponding to that operation. Then add code that checks for a denominator of zero before performing the divide operation.
For example, change this:
int a = b % c; // Divide by zero can happen here; |
to this:
int a; |
if (c != 0) { |
a = b % c; |
} else { |
a = 0; |
} |
Last updated: 2007-02-26