Crash capture and processing in Swift app

Source: Internet
Author: User

1. Why would crash

Common crash reasons are: access to the memory that has been freed, array out of bounds, use! Unpack the variable with a value of nil. When these conditions are encountered, the application has encountered a very serious unintended error and cannot continue running. When these illegal operations are detected by the operating system, the corresponding signal is sent to the application, and the default processing of these signals is to have the application exit directly (the signal value as the exit code). So there is the crash we see, the flash back.

Specific signal types and signaling mechanisms see UNIX Signal

2. How to capture and process crash

In swift3.0, we can register the processing logic for a particular signal by means of a downward adjustment.

 in print (s);})

In the processing function we generally do the following:

    • Get the call stack information
    • Related logic processing (such as saving the call stack to a file or database)
    • Restore signal processing functions to default settings
    • Call exit to exit the app

3. Get the Call stack information

The most valuable information for analyzing crash is the call stack. In Swift 3.0 we can invoke the Thread. Callstacksymbols to get the call stack information for the crash. (formerly through BackTrace and backtrace_symbols system call to get )

It is the thread that needs to be explained. The call stack returned by Callstacksymbols also contains the trigger code from crash to call thread. The call stack information between the Callstacksymbols can be selected for removal as needed.

Based on the above technical points, I have implemented two sets of Crashhandler, as well as sample programs, based on OC and Swift respectively. Code See: Https://github.com/lbwxly/CrashHandler

Crash capture and processing in Swift app

Related Article

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.