John Ryan
John Ryan

Reputation: 137

Xcode console error "Program received signal: "EXC_ARITHMETIC"" with division?

I have been recently using the Xcode console tool to build simple programs. What I am trying to do is set a value say "x" equal to a division of variables. Xcode seems to work with adding and subtracting but not with setting variables equal to division of variables. Here is my code for further reference:

scanf("%ix^2+%ix+%i", &h, &i, &j);

            k = h/m; <---- Error

            l = i - n;

            m = h/k; <---- Error

            n = i - l;

            l = j/n; <---- Error

        NSLog(@"(%ix+%i)(%ix+%i)", k, l, m, n);

Upvotes: 2

Views: 2798

Answers (1)

NIlesh Sharma
NIlesh Sharma

Reputation: 5655

EXC_ARITHMETIC (SIGFPE) It may happens because of various conditions like divide by zero, integer overflow, etc., and in your case it is most likely integer divide by zero I guess.

Edit: The problem is that it is not and exception, its a signal error so you can't handle it by exception handling. You need to find out a way for signal handling. See the accepted answer of this question C++ : Catch a divide by zero error for more information.


In an overall aspect division by zero is a logical error, you shouldn't let that happen at first so instead handling it, better try such type of situation should not occur.

Upvotes: 2

Related Questions