Method, system and readable storage medium for handling thread exceptions of iOS system

By using the SDK listener to identify and handle iOS system thread exceptions, the problem of program exceptions caused by non-main threads in iOS development is solved. This enables centralized management and rapid location of exceptions, reducing the time and trouble for developers to manually find exceptions.

CN115904767BActive Publication Date: 2026-07-03SHENZHEN IPI NETWORK TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN IPI NETWORK TECH CO LTD
Filing Date
2021-08-18
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

In iOS development, code executed on a non-main thread can cause program errors, stuttering, or crashes. The location of the exception is uncertain and difficult to manage centrally. Background threads modify the Auto Layout engine, requiring developers to manually find the location of the exception.

Method used

By constructing an SDK listener, identifying thread problem types, calling the corresponding exception handling methods, exchanging return results, and utilizing the underlying methods and functions provided by the runtime to ensure the program runs normally, the location of the exception is displayed in the console.

Benefits of technology

Centralized handling of exceptions avoids developers having to manually locate exceptions, improving exception location efficiency, reducing wasted time, and enabling unified classification, processing, and display of exceptions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115904767B_ABST
    Figure CN115904767B_ABST
Patent Text Reader

Abstract

This invention discloses a method, terminal, and readable storage medium for handling thread exceptions in an iOS system. The method includes: an SDK listener program monitoring exception reports from mobile applications; upon receiving an exception report, the listener program identifies the specific thread problem type and calls an exception handling method in the SDK corresponding to the identified thread problem type; the called exception handling method finds the instance method of the mobile application where the exception occurred; the exception handling method swaps the found instance method with a default return result and returns to the listener program; if the return fails, it uses a low-level method function provided by the runtime and swaps it with the default return result before returning to the listener program; the listener program uses the return result of the exception handling method to determine the exception location information. This invention centrally categorizes and handles program exception problems, avoiding the trouble and time wasted by developers in locating program exceptions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of Apple mobile application development, and more particularly to a method, terminal, and readable storage medium for handling thread exceptions in an iOS system. Background Technology

[0002] In the iOS development field, when encountering thread issues such as code that must be executed on the main thread actually being executed on a non-main thread, it can cause program errors, lag, or even app crashes. Developers need to troubleshoot the location of the abnormal code themselves.

[0003] The current exception checking methods have the following drawbacks: each developer needs to check the code for each error; due to the differences in the functionality of project modules, the location of the problem is uncertain; the location of the problem is too scattered, which is not conducive to centralized management; and the background thread will modify the automatic layout engine. Summary of the Invention

[0004] The technical problem to be solved by the present invention is to provide a method, terminal and readable storage medium for handling thread exceptions in iOS system, in view of the above-mentioned defects of the prior art.

[0005] The technical solution adopted by this invention to solve its technical problem is: to construct a method for handling thread exceptions in an iOS system, the method comprising:

[0006] The SDK's listener monitors for exception reports that occur in mobile applications.

[0007] After the listening program detects the exception report, it identifies the specific thread problem type and calls the exception handling method in the SDK that corresponds to the identified thread problem type.

[0008] The invoked exception handling method finds the instance method in which the mobile application encountered an exception;

[0009] The exception handling method will swap the found instance method with the default return result and return it to the listener. If the return fails, it will use the underlying method function provided by the runtime and swap it with the default return result before returning it to the listener.

[0010] The monitoring program determines the location information of the exception by the return result of the exception handling method.

[0011] Preferably, the method further includes: the monitoring program forcibly alerting the user to abnormal location information via the console and stopping the application at the location where the error code occurred.

[0012] Preferably, the method further includes:

[0013] The monitoring program predefines different thread problem types based on Mach exceptions and UNIX signals in the exception report, and defines different exception handling methods corresponding to the different thread problem types. Each exception handling method uniquely corresponds to one thread problem type.

[0014] Preferably, identifying the specific thread problem type includes: finding the corresponding thread problem type from different predefined thread problem types based on the Mach exceptions and UNIX signals in the exception report.

[0015] Preferably, the invoked exception handling method finds the instance method of the mobile application that has encountered an exception, including: the invoked exception handling method obtains a pointer to the exception class through assert() assertion, and then obtains the instance method corresponding to the pointer through class_addMethod.

[0016] In another aspect, the present invention also constructs a system for handling thread exceptions in an iOS system, including a processor and a memory, wherein the memory stores a computer program to be tested, and the computer program, when executed by the processor, implements the steps of the method described in any of the preceding claims.

[0017] In another aspect, the present invention provides a readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method described in any of the preceding claims.

[0018] The iOS system thread exception handling method, terminal, and readable storage medium of the present invention have the following beneficial effects: The exception location problem is solved by encapsulating an SDK; exception reporting is centrally handled using the SDK embedded in the application; and different thread problem types are defined. When an exception occurs, exceptions of the same type are handled by a unified exception handling method. That is, the present invention centrally categorizes and handles program exception problems, avoiding the trouble and time waste caused by developers locating program exceptions; and if the exception handling method returns a failure, it exchanges the underlying method function provided by the runtime with the default return result before returning, ensuring that no return exception occurs. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort:

[0020] Figure 1 This is a flowchart of the method for handling thread exceptions in the iOS system according to the present invention. Detailed Implementation

[0021] To facilitate understanding of the present invention, a more complete description will be given below with reference to the accompanying drawings. Typical embodiments of the invention are shown in the drawings. However, the invention can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.

[0022] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.

[0023] The general idea of ​​this invention is to embed an SDK when developing mobile applications, use the SDK to monitor and collect statistics on exceptions, and classify and process the exceptions, thereby avoiding the trouble and time wasted by developers in locating program exceptions.

[0024] To better understand the above technical solutions, the following will describe the above technical solutions in detail with reference to the accompanying drawings and specific embodiments. It should be understood that the embodiments of the present invention and the specific features in the embodiments are detailed descriptions of the technical solutions of this application, rather than limitations on the technical solutions of this application. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.

[0025] Example 1

[0026] refer to Figure 1 This embodiment discloses a method for handling thread exceptions in an iOS system, the method comprising:

[0027] S101: The SDK's listener program monitors for exception reports from mobile applications;

[0028] The SDK is embedded in the machine application, and the machine application is developed in the development tools.

[0029] S102: After the listening program detects the exception report, it identifies the specific thread problem type and calls the exception handling method in the SDK that corresponds to the identified thread problem type.

[0030] The monitoring program predefines different thread problem types based on Mach exceptions and UNIX signals in the exception report, and defines different exception handling methods corresponding to the different thread problem types. Each exception handling method uniquely corresponds to one thread problem type.

[0031] Specifically, Mach exceptions are prefixed with EXC_.

[0032] In this invention, the type of thread problem is determined by a combination of Mach exceptions and UNIX signals. For example, EXC_CRASH (SIGABRT) is a type of thread problem, and EXC_BAC_ACCESS (SIGSEGV) is a type of thread problem.

[0033] Therefore, based on the defined specific thread problem types, the identification of specific thread problem types specifically involves finding the corresponding thread problem type from the different predefined thread problem types according to the Mach exceptions and UNIX signals in the exception report.

[0034] S103: The invoked exception handling method finds the instance method in which the mobile application has encountered an exception;

[0035] Specifically, the invoked exception handling method finds the instance method of the mobile application that caused the exception, including: the invoked exception handling method obtains a pointer to the exception class through assert() assertion, and then obtains the instance method corresponding to the pointer through class_addMethod, the instance method carrying the exception class name and class method.

[0036] S104: The exception handling method will swap the found instance method with the default return result and return it to the listener. If the return fails, it will use the underlying method function provided by the runtime to swap it with the default return result and return it to the listener.

[0037] Each exception handling method is configured with a return function, which has a default return result. In this embodiment, the instance method obtained in step S103 is swapped with the default return result, thus returning the instance method to the listener. However, if no valid instance method is found in step S103, the program will fail to run. Therefore, this embodiment proposes using a low-level method function provided by the runtime to swap with the default return result before returning to the listener, thus ensuring the normal operation of the program.

[0038] S105: The listening program determines the exception location information based on the return result of the exception handling method.

[0039] Since the returned result is actually an instance method in S103, and the instance method carries the exception class name and class method, the location information of the exception can be easily determined.

[0040] S106: The monitoring program forcibly warns the user of abnormal location information through the console and stops the application at the location where the error code appears.

[0041] The console here refers to the display interface of the development tools, and the development tools refer to the development tools used to develop the mobile application.

[0042] As described above, this embodiment solves the problem of exception location by encapsulating an SDK. It utilizes the SDK embedded in the application to centrally handle exception reporting, and defines different thread problem types. These thread problems are summarized and categorized for clearer processing. When an exception occurs, exceptions of the same type are handled by a unified exception handling method. In other words, this invention centrally categorizes and handles program exceptions. When compiling and running the mobile application, developers do not need to manually search for and locate program exceptions, avoiding the hassle and time wasted by developers. The SDK uniformly handles exceptions and displays them in the console. Furthermore, the exception categorization process also filters and selects exceptions based on their type (e.g., EXC_CRASH(SIGABRT)); and a unified display format for exceptions is implemented in the console.

[0043] Example 2

[0044] This embodiment discloses a system for handling thread exceptions in an iOS system, including a processor and a memory. The memory stores a computer program to be tested. When the computer program is executed by the processor, it implements the steps of the method described in Embodiment 1. For details of the implementation process, please refer to the description of the above method embodiments, which will not be repeated here.

[0045] Example 3

[0046] This embodiment discloses a readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the steps of the method described in Embodiment 1. For details of the implementation process, please refer to the description of the above method embodiments, which will not be repeated here.

[0047] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims. All of these forms are within the protection scope of the present invention.

Claims

1. A method for iOS system thread exception handling, the method comprising: The method includes: The SDK's listener monitors for exception reports that occur in mobile applications. After the listening program detects the exception report, it identifies the specific thread problem type and calls the exception handling method in the SDK that corresponds to the identified thread problem type. The invoked exception handling method finds the instance method in which the mobile application encountered an exception; The exception handling method will swap the found instance method with the default return result and return it to the listener. If the return fails, it will use the underlying method function provided by the runtime and swap it with the default return result before returning it to the listener. The monitoring program determines the location information of the exception by the return result of the exception handling method; The method for handling iOS system thread exceptions further includes: the listener program forcibly alerts the user to the location of the exception through the console and stops the application at the location where the error code occurs; The methods for handling iOS system thread exceptions also include: The monitoring program predefines different thread problem types based on Mach exceptions and UNIX signals in the exception report, and defines different exception handling methods corresponding to the different thread problem types. Each exception handling method uniquely corresponds to one thread problem type. The identification of specific thread problem types includes: finding the corresponding thread problem type from different predefined thread problem types based on Mach exceptions and UNIX signals in the exception report; The invoked exception handling method finds the instance method of the mobile application that has encountered an exception, including: the invoked exception handling method obtains a pointer to the exception class through assert() assertion, and then obtains the instance method corresponding to the pointer through class_addMethod.

2. A system for handling thread exceptions in an iOS system, characterized in that, It includes a processor and a memory, the memory storing a computer program to be tested, which, when executed by the processor, implements the steps of the method as described in claim 1.

3. A readable storage medium, characterized in that, The system contains a computer program that, when executed by a processor, implements the steps of the method as described in claim 1.