Libc++abi.dylib:terminate_handler unexpectedly threw an exception error summary

Source: Internet
Author: User
Tags vars

Objective

When we run the Xcode project, we sometimes encounter "Libc++abi.dylib:terminate_handler unexpectedly threw an exception" error, The app inexplicably crash off, enter the BT command in the console, view the call stack, and the result is confused:

Analysis

Now the only point of information is Libc++abi.dylib, What exactly does this library do? From the suffix view, is a dynamic library, then will it be because of some dynamic errors? By experience, the general dynamic error is basically due to the dynamic type error, in the Object-c language, the possibility of a dynamic type error can exist in the transformation between the immutable type and the mutable type, then our error-checking scope will be limited to the immutable type and the variable type conversion, Are we modifying a immutable type? Of course, the compiler is not so silly, if directly to an immutable type modification operation, will be directly error, then there is another possibility, the program assigns an immutable type to a mutable type, and then modifies the mutable type, which can be checked by static, but dynamically run, A type error occurs. Based on the above analysis, we can track breakpoints, we will find that the program in the Mutable object to add, set and other operations, and this object is actually assigned to an immutable object. A common case is to assign a Nsarray object to a Nsmutablearray object, then delete, add, and so on, or assign a Nsdictionary object to a Nsmutabledictionary object. Then the set and other operations are performed.

The workaround is simple, and the type conversion is done when assigning values:  
    1. Mutablearr: Variable array arr: non-variable group
    2. Mutabledic: mutable dictionary dic: immutable Dictionary
    3. Variable type conversions are required when assigning a value
    4. Mutablearr = [Nsmutablearray Arraywitharray:arr];
    5. Mutabledic = [Nsmutabledictionary dictionarywithdictionary:dic];
    6. The array may be empty,

Libc++abi.dylib:terminate_handler unexpectedly threw an exception error summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.