Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does Error "Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" mean?

I got this error:

Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

How can I solve this? The code works normally, but in the calculator when I click the only equal button, it gives that error.

@IBAction func equals(sender: AnyObject) {

    secondNumber = Screen.text!.toInt()!  // here it shows an error which is "Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)"

    if operation == "+"{
        result = firstNumber + secondNumber
    }
    else if operation == "-" {
        result = firstNumber - secondNumber
    }
    else if operation == "x" {
        result = firstNumber * secondNumber
    }
    else {
        result = firstNumber / secondNumber
    }
    Screen.text = "\(result)"
}
like image 670
legolas Avatar asked Mar 02 '15 07:03

legolas


3 Answers

This line

secondNumber = Screen.text!.toInt()!

means: Get the Screen object, get the text property and please crash if it doesn't exist, then get the text converted to an integer, and please crash if it doesn't exist.

That's what the ! means: "I am sure this thing exists, so please crash if it doesn't". And crash is what it did.

like image 55
gnasher729 Avatar answered Nov 17 '22 04:11

gnasher729


Generally, EXC_BAD_INSTRUCTION means that there was an assertion failure in your code. A wild guess, your Screen.text is not an integer. Double check its type.

like image 39
Ashraf Tawfeeq Avatar answered Nov 17 '22 04:11

Ashraf Tawfeeq


Mine was about

dispatch_group_leave(group)

was inside if closure in block. I just moved it out of closure.

like image 10
alicanbatur Avatar answered Nov 17 '22 03:11

alicanbatur