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

Source: Internet
Author: User

Objective

When we run 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 the hell is this library for? 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.

SolveThe solution is simple, when assigning a value, type conversion:
    Mutablearr: Variable array arr: Immutable group    //mutabledic: Variable dictionary dic: immutable dictionary    //assignment requires a mutable type conversion    Mutablearr = [Nsmutablearray Arraywitharray:arr];    Mutabledic = [Nsmutabledictionary dictionarywithdictionary:dic];





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.