CN112698980A - Exception handling method, electronic device, and storage medium - Google Patents

Exception handling method, electronic device, and storage medium Download PDF

Info

Publication number
CN112698980A
CN112698980A CN202110009427.8A CN202110009427A CN112698980A CN 112698980 A CN112698980 A CN 112698980A CN 202110009427 A CN202110009427 A CN 202110009427A CN 112698980 A CN112698980 A CN 112698980A
Authority
CN
China
Prior art keywords
exception
abnormal
exception handling
information
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110009427.8A
Other languages
Chinese (zh)
Inventor
梁少泽
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wangsu Science and Technology Co Ltd
Original Assignee
Wangsu Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wangsu Science and Technology Co Ltd filed Critical Wangsu Science and Technology Co Ltd
Priority to CN202110009427.8A priority Critical patent/CN112698980A/en
Publication of CN112698980A publication Critical patent/CN112698980A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/0706Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation the processing taking place on a specific hardware platform or in a specific software environment
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/0793Remedial or corrective actions

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention relates to the technical field of computers, and discloses an exception handling method, electronic equipment and a storage medium. In the invention, an abnormal message which is triggered when a code is abnormal in the running process of an application program and is reported to an operating system is intercepted; acquiring abnormal information of the code abnormality according to the intercepted abnormal information, and inquiring abnormal processing operation matched with the abnormal information of the code abnormality in the abnormal processing configuration information; the exception handling configuration information comprises a corresponding relation between exception information and exception handling operation; and if the matched exception handling operation is inquired, executing the matched exception handling operation. According to the method and the device, the problem that the operating system triggers and forcibly interrupts the operation of the application program process to cause program crash can be avoided due to the fact that the application program directly sends the abnormal message to the operating system, great influence on the application program due to small program bugs is avoided, and user experience is improved.

Description

Exception handling method, electronic device, and storage medium
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to an exception handling method, electronic equipment and a storage medium.
Background
With the rapid development of the mobile internet era, operating systems in the market are also rapidly developed at present, and each operating system is also rapidly occupying the market, for example, Android and iOS operating systems are two main operating systems commonly used at present. The common operating system processes the application program in a substantially same manner, for example, when the application program has a bug at a code level, which may cause the application program to be abnormal, the operating system defaults that an exception handling mechanism at the code level of the application program is to forcibly interrupt the application program process, which is commonly referred to as a killing process, so that the application program appears as a program crash.
However, in many cases, the exception at the application code level is different from a functional exception or a configuration exception, and the exception of the application at the code level is often caused by some small program bugs, which do not have a great influence on the use of the application, such as null pointer, array out-of-bounds, and the like.
Disclosure of Invention
An object of the embodiments of the present invention is to provide an exception handling method, an electronic device, and a storage medium, which can ignore or avoid some program bugs without updating program codes, and avoid that a small program bug has a large influence on an application program.
To solve the above technical problem, an embodiment of the present invention provides an exception handling method, including: intercepting an abnormal message which is triggered when a code is abnormal in the running process of an application program and is reported to an operating system; acquiring abnormal information of the abnormality according to the intercepted abnormal information, and inquiring abnormal processing operation matched with the abnormal information in abnormal processing configuration information; the exception handling configuration information comprises a corresponding relation between exception information and exception handling operation; and if the matched exception handling operation is inquired, executing the matched exception handling operation.
An embodiment of the present invention further provides an electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the above-described exception handling method.
Embodiments of the present invention also provide a computer-readable storage medium storing a computer program, which when executed by a processor implements the above-described exception handling method.
Compared with the related technology, the embodiment of the invention intercepts the abnormal information reported to the operating system triggered when the code abnormality occurs in the running process of the application program, avoids the problem that the operating system directly uses the default processing mode of forcibly interrupting the application program process to process the code abnormality to cause the application program crash because the application program directly sends the abnormal information to the operating system, acquires the abnormal information of the code abnormality according to the intercepted abnormal information, inquires the abnormal processing operation matched with the abnormal information in the abnormal processing configuration information, executes the matched abnormal processing operation instead of directly forcibly interrupting the application program process if the matched abnormal processing operation is inquired, reduces the influence of small program bugs on the program crash of the application program, and can ignore or avoid some program bugs without updating the program code, the user experience is optimized, the customer loss is reduced, and time is won for a developer to repair the program bugs.
In addition, the abnormality information includes: environmental information of the occurrence of the code exception and a reason of the occurrence of the code exception; the exception handling configuration information comprises a plurality of configuration items, and each configuration item comprises exception handling operation, environment information and an exception reason; the querying, in the exception handling configuration information, the exception handling operation matched with the exception information includes: and inquiring configuration items matched with the environment information of the code exception and the reason of the code exception in the exception configuration information, and taking exception handling operation included in the inquired configuration items as the matched exception handling operation. In the implementation, the reason of the code exception is considered, the environmental information of the code exception is considered, and the exception handling operation is matched by combining the environmental information of the code exception and the reason of the code exception, so that the code exception is handled more pertinently and accurately.
In addition, after the exception handling operation matched with the exception information is inquired in the exception handling configuration information, the method further comprises the following steps: and if the matched exception handling operation is not inquired, performing forced interrupt application program process operation on the process generating the code exception. In the implementation, when the exception handling operation is not matched, the default exception handling method of the operating system is called back, namely, the application program process is forcibly interrupted, so that the problem that the operation of other processes is influenced by serious exception is avoided, and further, the use of the electronic equipment by a user is influenced.
In addition, after the performing the matched exception handling operation or after the performing the operation of forcibly interrupting the application program process, the method further includes: acquiring an exception handling result for handling the code exception; determining reported data according to the classification result of the code exception and the exception handling result; wherein the classification result of the code exception is determined according to the exception information of the code exception; and sending the reported data to a server so that the server can count the reported data to obtain a statistical result of abnormal processing. The server can count according to the reported data to obtain the exception handling effect by reporting the data to the server, so that the exception configuration data can be dynamically adjusted and updated according to the exception handling effect, in addition, the code exceptions are classified, so that the exceptions of different types can be analyzed in the counting process, the configuration file can be adjusted, and the adjusted configuration file can better meet the exception handling requirement.
In addition, before intercepting an exception message reported to the operating system, which is triggered when a code exception occurs in the running process of the application program, the method further includes: registering abnormal monitoring, wherein the abnormal monitoring is used for monitoring the abnormal message; the exception message carries a semaphore used for acquiring stack information of code exception; and replacing the operation of forcibly interrupting the application program process in the operating system with the exception handling operation. By registering abnormal monitoring, the operation of forcibly interrupting the application program process of the operating system is replaced by abnormal processing operation, so that when monitoring abnormal conditions, abnormal messages are not directly reported to an abnormal processing module of the operating system but reported to an abnormal processing system, and when code abnormal conditions occur, the abnormal processing system intercepts the abnormal messages and processes the abnormal conditions according to the abnormal processing operation.
In addition, before intercepting an exception message reported to the operating system, which is triggered when a code exception occurs in the running process of the application program, the method further includes: locally inquiring abnormal configuration data of the application program, or requesting the abnormal configuration data of the application program from a server; and analyzing the abnormal configuration data to obtain the abnormal processing configuration information, so that the abnormal configuration data can be flexibly obtained, and obtaining new abnormal processing configuration information by analyzing the obtained abnormal configuration data.
In addition, if the abnormal configuration data of the application program is requested from the server, in the sent abnormal configuration data request for requesting the abnormal configuration data, the summary information of the abnormal configuration data corresponding to the abnormal processing configuration information of the application program, which is obtained through analysis, is carried, so that the server can determine whether an updated version of the abnormal processing configuration information exists or not, and feed back the updated version after the updated version is determined. In the implementation, the server is convenient to determine the version of the abnormal configuration data of the abnormal processing system so as to determine whether to send the abnormal configuration data of the latest version, thereby avoiding repeatedly acquiring the same abnormal configuration data, and enabling the abnormal processing configuration information analyzed by the abnormal configuration data of the abnormal processing system to keep the latest version.
Additionally, the code exception includes any one of, and combinations of: the non-main thread is abnormal, the user interface is abnormal, and the array is abnormal when the array is out of bounds: when the code exception is a non-main thread exception, the exception handling operation is a thread with an interrupt exception; when the code exception is that the user interface is abnormal, the exception handling operation is to close the exception interface; and when the code exception is an array out-of-range exception, the exception handling operation is to return interpolation. The non-main line exception, the user interface exception and the array out-of-range exception are all exceptions caused in the running process of the application program due to code bugs, and the exception at the code level of the program can be processed more pertinently through exception processing operation configured on the exceptions without updating codes by developers.
Drawings
One or more embodiments are illustrated by the corresponding figures in the drawings, which are not meant to be limiting.
FIG. 1 is a flow chart of an exception handling method according to a first embodiment of the present invention;
FIG. 2 is a schematic diagram of exception handling system initialization according to a first embodiment of the present invention;
FIG. 3 is a flow chart of an exception handling method according to a second embodiment of the present invention;
FIG. 4 is a diagram of exception protection and statistics performed by the exception handling system in accordance with a second embodiment of the present invention;
FIG. 5 is a schematic diagram of an exception handling apparatus according to a third embodiment of the present invention;
fig. 6 is a schematic structural diagram of an electronic device in a fourth embodiment according to the present invention.
DETAILED DESCRIPTION OF EMBODIMENT (S) OF INVENTION
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the embodiments of the present invention will be described in detail with reference to the accompanying drawings. However, it will be appreciated by those of ordinary skill in the art that in various embodiments of the invention, numerous technical details are set forth in order to provide a better understanding of the present application. However, the technical solution claimed in the present application can be implemented without these technical details and various changes and modifications based on the following embodiments. The following embodiments are divided for convenience of description, and should not constitute any limitation to the specific implementation manner of the present invention, and the embodiments may be mutually incorporated and referred to without contradiction.
A first embodiment of the present invention relates to an exception handling method. The exception handling method of the embodiment may be applied to an electronic device, such as a mobile phone, a tablet computer, and the like, in which an application program is installed, but is not limited thereto. The exception handling method of the embodiment comprises the following steps: intercepting an abnormal message which is triggered when a code is abnormal in the running process of an application program and is reported to an operating system; according to the intercepted abnormal message, inquiring abnormal processing operation matched with the abnormal information in the abnormal processing configuration information; the exception handling configuration information comprises a corresponding relation between exception information and exception handling operation; and if the matched exception handling operation is inquired, executing the matched exception handling operation. In addition, the embodiment can ignore or avoid program bugs under the condition of not updating program codes, optimize user experience, reduce customer loss, and strive for time for developers to repair the program bugs.
The flow of the exception handling method of the present embodiment is shown in fig. 1. The following describes the implementation details of the exception handling method of this embodiment in detail with reference to fig. 1, and the following description is only provided for the sake of understanding, and is not necessary for implementing this embodiment.
Step 101, intercepting an abnormal message which is triggered when a code abnormality occurs in the running process of an application program and reported to an operating system.
When the code of the application has some bug bugs, these bugs may cause an exception to occur during the running of the application, that is, an exception at the code level, and the following is an exemplary brief description of an exception caused by the code, but is not limited to this.
(1) A click is abnormal. For example, when a picture is clicked to display a large picture, the resource of the picture is a null value, the click processing method does not involve the amplification processing of the picture resource which is the null value, and at this time, click abnormality occurs.
(2) And skipping to the new interface exception. For example, the new interface to be jumped is not declared in the program, the program logic exception of the created new interface, or the logic exception in the life cycle of the interface can cause the exception of the new interface to be jumped.
(3) A child thread exception is a logical exception that occurs in a child thread.
(4) No arbitration process is performed.
(5) The user interface UI (user interface) is operated in a non-main thread. Android and iOS operating systems prohibit UI-related operations on non-main threads based on thread synchronization and thread security issues, as well as complexity of system design. An exception may occur when the user interface is operated in a non-main thread.
(6) The array is out of bounds. For example, only 10 elements are defined and stored in an array of a certain section of code of an application program, and the 11 th array element accessed when the array element is accessed can trigger an array out-of-range exception.
When the process of the application program is abnormal, in the related art, the process may send an abnormal message to an exception handling mechanism of the operating system, where the abnormal message may carry a semaphore, the abnormal stack information may be obtained according to the semaphore, the abnormal information may be obtained according to the abnormal stack information, the exception handling mechanism of the operating system may identify the process that generates the exception, and directly execute the forced interrupt application program process operation, thereby ending the process that generates the exception, so that the application program crashes. In order to repair a program code bug, an application program developer updates a code, a user can download a new version of a released application program to repair an exception or use a hot repair technology to download a repair code package from a network to repair an exception, but the application program can be on-line only after being checked by an application market from online triggering of the program bug to discovery of the developer, and the application program is repaired by the developer to be on-line, so that a long process is needed, especially an Android and iOS platform, and the application program can be on-line.
Therefore, in this embodiment, the exception message of the process is intercepted, so that the exception message is not directly sent to the exception handling mechanism of the operating system, thereby avoiding that the operating system directly executes the operation of forcibly interrupting the application program process, and after the exception message is intercepted, the step 102 is executed.
And 102, acquiring abnormal information of the code abnormality according to the intercepted abnormal information, and inquiring abnormal processing operation matched with the abnormal information in the abnormal processing configuration information. The exception handling configuration information comprises a corresponding relation between exception information and exception handling operation.
In one example, the exception information includes: environmental information of code exception and reason of code exception; the exception handling configuration information comprises a plurality of configuration items, and each configuration item comprises exception handling operation, environment information and an exception reason; and inquiring configuration items matched with the environment information of the code exception and the reason of the code exception in the exception configuration information, and taking the exception handling operation included in the inquired configuration items as matched exception handling operation.
Illustratively, after an exception message of a code exception is intercepted, exception stack information is obtained according to the exception message, and then the exception handling system obtains exception information from the exception stack information and matches the exception information with exception handling configuration information. The exception information includes environment information where a code exception occurs, and the environment information may include: the device information of the electronic device generating the abnormality, such as an operating system installed on the electronic device, an operating system version number, a device architecture, that is, whether the device is 32-bit or 64-bit, a device model; the application information of the application program generating the code exception, such as the name of an application package and an application interface where the exception occurs; network information of a network where the generated abnormality is located, such as a network type, an operator, network quality, and the like; the Exception information also includes the reason of the code Exception, and the reason of the code Exception can be positioned to the code information of the Exception, such as a library of the Exception, for example, frame, jar, etc., the function of the Exception, the type of the Exception, for example, the type of Exception, and the thread of the Exception. The exception handling configuration information comprises a plurality of configuration items, and each configuration item has a corresponding relation between a group of exception information and exception handling operation.
In one example, the exception handling operation may include an exception handling policy, such as: ignoring the thread with exception and interrupting the exception, closing the exception interface, returning interpolation, forwarding and calling other methods, namely functions and the like. For example, the thread in which the exception occurs is a non-main thread, and the exception handling policy may be configured to interrupt the thread in which the exception occurs; when an exception associated with the user interface UI occurs, the exception handling policy may be configured to close the exception interface; when an array out-of-range exception occurs, the exception handling policy may be configured to return an interpolation, and the returned interpolation may also be set, for example, to return a null value.
For example, if the intercepted is an exception message of the running application program a, the exception handling configuration information of the application program a is obtained. The exception handling configuration information may include a plurality of configuration items, each configuration item including an exception handling operation, environmental information, and an exception cause. For example, the exception handling configuration information includes:
(1) configuration item 1: the environment information of the exception occurrence is that the process of the application program A running on the Android10 system is abnormal under the 4G network, the reason of the abnormality occurrence is null pointer exception, namely the exception type is NullPointerException, and the corresponding exception handling policy is the thread with the exception caused by interruption;
(2) configuration item 2: the environment information of the exception occurrence is that the process of the application program A running on the iOS13 platform is abnormal, the exception is caused by the out-of-bounds of the BOOL type array in the DBPathRecognizer code library used in the application program A, namely the exception type is IndexOutOfBoundsException, and the corresponding exception handling policy is to return interpolation NO.
Therefore, if the abnormal information is found to be that the application program a running on the Android10 platform is abnormal in the 4G network, and the reason for the abnormal is that the null pointer is abnormal, the matched exception handling policy is as follows: interrupting the thread with the exception; if the abnormal exception information is inquired to indicate that the process of the application program A running on the iOS13 platform is abnormal, and the exception reason is that a BOOL type array in a DBPathRecognizer code library used in the application program A is out of range, the matched exception handling strategy is to return interpolation NO. If the abnormal information is that the application program A running on the Android10 platform is abnormal in the 5G network, the reason for the abnormal information is click abnormality, and the configuration item including the abnormal information cannot be found in the abnormal processing configuration information, that is, the corresponding relation cannot be found, then the matched abnormal processing operation cannot be found.
In another example, the exception handling operation in the exception handling configuration information further includes an indication of whether to perform exception protection, that is, the exception handling operation in the exception handling configuration information includes: exception handling policies and whether to guard. When the exception handling operation is not to perform exception protection, the configuration item may not record the corresponding exception handling policy. When inquiring, the environment information of the abnormal occurrence and the reason of the abnormal occurrence, namely the abnormal information corresponding to the generated abnormal is compared with the abnormal information in the configuration item, so as to obtain the matched abnormal processing operation.
It should be noted that, when the abnormal processing operation matched with the abnormal information is queried, a plurality of matched abnormal processing operations may be queried, and the executed abnormal processing operation may be set according to a requirement, for example, one matched abnormal processing operation is randomly selected.
After step 102 is executed, if the matched exception handling operation is found, that is, the matching is successful, step 103 is executed.
And 103, executing the matched exception handling operation.
In one example, when matching the exception handling operation, if the matched exception handling operation only includes the exception handling policy, the exception handling policy is executed to handle the exception. For example, if the found exception handling policy is the exception handling policy in the configuration item 1, invoking an exception handling function corresponding to the exception handling policy to implement the thread with the exception; if the found exception handling policy is the exception handling policy in the configuration item 2, calling the corresponding exception handling function to realize the operation of returning the difference NO to the process with the exception.
In another example, when an exception handling operation is matched, if the matched exception handling operation includes an exception handling policy and an indication for performing exception protection, the exception handling policy in the exception handling operation is used for handling an exception; if the matched exception handling operation comprises an indication of not carrying out exception protection, the exception is handed to the process handling of the operating system, namely, the process operation of the application program is directly interrupted by force. By including the indication of whether to perform exception protection in the exception handling operation, the exception handling policy is not used to handle the exception when the bug of the exception is large, but the application program process is directly and forcibly interrupted to handle, so that the influence on other application programs is avoided.
After step 102 is performed, if no matching exception handling operation is found, step 104 may be performed.
And 104, carrying out forced interrupt application program process operation on the process generating the code exception.
And if the matched exception handling strategy is not found, executing the forced interrupt application program process operation. In this case, the abnormal exception message may be sent to an exception handling mechanism of the operating system, and the process may be subjected to a process of the application program by forced interrupt, so as to avoid that the abnormal process occupies software and hardware resources or affects the operation of other processes, thereby affecting the use of the electronic device.
In this embodiment, taking the exception handling system installed in the electronic device as an example to execute the above exception handling method, before the exception handling system is used to handle an exception, the exception handling system needs to be initialized, and a flow of initializing the exception handling system is briefly described below with reference to fig. 2.
For example, after the application program is started, a start interface of the exception handling system is called, and the exception handling system starts to execute initialization operation.
In one example, the application program is queried for anomalous configuration data locally, i.e., in the local configuration of FIG. 2, or requested from a server; and analyzing the abnormal configuration data to obtain the abnormal processing configuration information. That is, the abnormal configuration data may be obtained from a local query or a server.
For example, if the server is requested for the abnormal configuration data of the application, i.e. the pull configuration, the exception handling system sends an abnormal configuration data request to the server, and the abnormal configuration data request may include the application information. The application information may include the version of the application, the type of device on which the application is installed, and the like. The server determines abnormal configuration data corresponding to the application program according to the application program information sent by the application program, the server sends abnormal configuration data, and the electronic equipment provided with the abnormal configuration data receives the abnormal configuration data. And analyzing the exception configuration data to obtain exception handling configuration information for handling the exception of the application program, and storing the exception handling configuration information into exception handling configuration, wherein the exception handling configuration can be a storage directory of the application program.
In an example, in the abnormal configuration data request for requesting the abnormal configuration data, the request may further carry summary information of the abnormal configuration data corresponding to the analyzed abnormal processing configuration information of the application program, so that the server determines whether an updated version of the abnormal processing configuration information exists, and feeds back the updated version after determining that the updated version exists. The summary information of the abnormal configuration data may be understood as an identifier of the abnormal configuration data, and may be specifically obtained by using an MD5 information summary Algorithm (Message-Digest Algorithm 5). The server receives the abnormal configuration data request, determines the abnormal configuration data according to the application information, compares the MD5 abstract of the determined abnormal configuration data with the MD5 abstract of the abnormal configuration data request, if the MD5 abstract of the determined abnormal configuration data is the same as the MD5 abstract of the abnormal configuration data request, proves that the abnormal configuration information in the abnormal processing system is the latest version, the server does not transmit the abnormal configuration data to the electronic equipment provided with the abnormal processing system, processes the abnormality by using the existing abnormal configuration information in the storage directory of the application program when the abnormal configuration is processed, if the MD5 abstract of the determined abnormal configuration data in the server is not the same as the MD5 abstract of the abnormal configuration data request, the server transmits the latest version of the abnormal configuration data to the electronic equipment provided with the abnormal processing system, and the abnormal configuration data transmitted by the server is analyzed by the abnormal configuration system to obtain the abnormal configuration, the abnormal configuration information is stored in the storage directory of the application program, the purpose of updating is achieved, the problem that the abnormal configuration information in the server is repeated due to repeated acquisition of the abnormal configuration data is avoided, storage resources are saved, and the abnormal configuration information is guaranteed to be the latest updated version, so that the abnormal configuration information is more accurately processed according to the configuration items in the abnormal configuration information. That is, when the abnormal configuration data is updated, the abnormal configuration data is acquired, the abnormal configuration processing information obtained by analysis is stored in the storage directory of the application program, and when the abnormal configuration data is not updated, the existing abnormal configuration processing information in the application storage directory is used for performing abnormal processing.
In the system initialization process, the exception initialization system is required to monitor the exception of the application program, exception monitoring is required to be registered, so that the exception message of the application program can be monitored when the application program is abnormal, and exception handling operation is required to be replaced in order to intercept the exception message when the application program is abnormal, namely, the operation of forcibly interrupting the application program process in the operating system is replaced by the exception handling operation. Such as a response function for replacing an abnormal message, a processing method, and a forwarding method for intercepting a message. By registering abnormal monitoring, monitoring abnormal messages and replacing the operation of the forced interrupt application program process of the operating system with abnormal processing operation, the abnormal messages are not directly reported to an abnormal processing module of the operating system but reported to an abnormal processing system when monitoring abnormal, so that the abnormal processing system intercepts the abnormal messages and processes the abnormal according to the abnormal processing operation when code abnormal occurs.
In this embodiment, when an application calls a start interface of an exception handling system, the exception handling system performs an initialization operation, in order to monitor when an exception occurs in the application, a listener is registered during the initialization process, and in order to prevent an exception message of the application from being directly sent to an exception handling mechanism of the operating system, this embodiment changes a reporting path of the exception message and sends an exception configuration data request, where the exception configuration data request carries summary information to avoid repeatedly acquiring the same exception configuration data, and when an exception occurs in the application, the exception message of the application is intercepted, so that the application is prevented from directly sending the exception to the operating system, and the operating system directly uses a default exception handling method of the operating system to handle the exception, thereby causing program crash. According to the intercepted exception message, the exception handling operation matched with the exception information is inquired in the exception handling configuration information, if the matched exception handling operation is inquired, the matched exception handling operation is executed instead of directly and forcibly interrupting the application program process, the influence of small program bugs on the application program is avoided, some program bugs can be ignored or avoided under the condition that program codes do not need to be updated, the user experience is optimized, the loss of clients is reduced, and time is also strived for developers to repair the program bugs.
A second embodiment of the present invention relates to an exception handling method. The second embodiment is substantially the same as the first embodiment, with the main differences being: in the second embodiment of the present invention, after an occurrence of an exception is handled, an exception handling result of the exception is acquired; determining reported data according to the abnormal classification result and the abnormal processing result; and sending the reported data to a server for the server to count the reported data to obtain a statistical result of exception handling, wherein a specific flow is shown in fig. 3.
Step 301, intercepting an exception message reported to an operating system, which is triggered when a code exception occurs in the running process of an application program. Step 301 is substantially the same as step 101, and will not be described herein again.
And step 302, acquiring abnormal information of the code abnormality according to the abnormal information, and classifying the abnormality according to the abnormal information to obtain an abnormal classification result.
Illustratively, the exception handling system monitors an exception, acquires exception information according to the exception information after intercepting the exception information, and then classifies the exception according to the exception information. The classification can be based on the exception type, the thread triggering the exception, the code base where the exception is located, the stack called by the exception, the network type of the exception, etc. For example, if the classification basis is an exception type, and the exception type to which the generated exception belongs is an array out-of-bounds exception, the classification result of the exception is an array out-of-bounds; if the classification basis is the abnormal network type and the network where the generated abnormality is located is 4G, the classification result is 4G; if the classification basis is the abnormal type and the thread triggering the abnormal, the thread with the abnormal is the thread A, the abnormal type is the non-main thread operation interface, the classification result is the thread A, and the non-main thread operation interface is abnormal. The classification basis can be adjusted according to the actual use condition.
Step 303, querying the exception handling operation matched with the exception information in the exception handling configuration information. If the matched exception handling operation is found, a successful matching result is obtained, step 304 is executed, and if the matched exception handling operation is not found, a failed matching result is obtained, and step 305 is executed. Step 303 is substantially the same as step 102, and is not described herein again.
And step 304, executing the matched exception handling operation to obtain an exception handling result.
In one example, when the exception handling operation is matched, if the matched exception handling operation only includes the exception handling policy, the exception handling policy is executed to handle the exception, if the exception handling is successful, that is, after the exception handling is performed, the application program does not crash, the obtained exception handling result is that the protection is performed and the exception handling is successful, and if the handling is failed, that is, after the handling is performed, the application program crashes, the obtained exception handling result is that the protection is performed and the exception handling is failed.
In another example, when the exception handling operation is matched, if the exception handling operation includes an indication for performing exception protection and an exception handling policy, the exception is handled according to the exception handling policy in the exception handling operation, and an exception handling result that fails or succeeds in performing protection is obtained, and if the matched exception handling operation includes an indication for not performing exception protection, the exception handling result is that the exception protection is not performed.
If the match fails, i.e., no exception handling operation is matched, step 305 is performed.
And 305, performing forced interrupt application program process operation on the abnormal process to obtain an exception handling result.
Illustratively, after the matching fails, the default exception handling operation of the operating system is called back, that is, the application program process is forcibly interrupted, and after the application program process is interrupted, the exception handling result is that no exception protection is performed.
And step 306, obtaining reported data according to the abnormal classification result and the abnormal processing result.
Illustratively, the report data is obtained by combining the exception handling result, such as the classification result of the exception, which is not protected by the exception, which fails to protect, or which succeeds in protecting, with the exception.
In an example, the reporting data may further include: the application information corresponding to the application program with the abnormality and the device information corresponding to the electronic device with the abnormality, that is, the reported data includes: exception handling results, exception classification results, application information corresponding to the application program in which the exception occurred, and device information corresponding to the electronic device in which the exception was located.
For example, the report data further includes application information corresponding to the application program with the exception and device information corresponding to the device with the exception, and the report data is as follows: the exception is generated in an application program A running on an Android10 platform, an interface where the exception occurs is a UI1, the exception classification result is that the thread A occurs in a non-main thread operation interface, and the exception processing result is that protection is successfully performed.
In one example, reporting the data may further include: and (6) matching results. That is, the exception handling operation matched with the abnormal exception information is inquired in the exception handling configuration information, if the matched exception handling operation is inquired, the matching result is successful, otherwise, the matching result is failed. It should be noted that the reported data may also include other exception handling and exception related information, which may be set according to requirements, and is not limited herein.
Step 307, sending the reported data to a server. The exception handling system reports the reported data to the server, and the server can carry out statistics according to the reported data.
Illustratively, the server may store the received reported data into a database, and count the crash rate, the abnormal protection rate, the abnormal unprotected rate of the application program, the crash rate of the application program after protection processing, the device where the crashed application program is located, the network where the crashed application program is located, the success rate after protection processing, and the like according to the data in the database. The server displays the calculated data on a server platform, and can also display comparison data before and after the abnormal configuration processing system is used, so that developers can visually compare the protection effect, update abnormal configuration data aiming at the protection effect, namely, realize the dynamic update of the abnormal configuration data, the electronic equipment can conveniently acquire the updated abnormal configuration data, more comprehensive code abnormal processing operation can be realized according to the dynamically updated abnormal configuration data, and the influence of program crash caused by the abnormal application program codes is reduced. For example, as seen from the statistical data, when the crash rate of the application program is high due to the generation of the abnormal type B on the device a, the abnormal type B generated by the device a may be configured, and the abnormal configuration data may be updated, so as to achieve better abnormal protection.
Fig. 4 is a schematic diagram illustrating protection and statistical reporting of an exception in conjunction with an exception handling system.
When the exception is triggered, performing an exception capturing operation, namely executing the step 301, classifying the exception after capturing the exception to obtain a classification result, and obtaining application information corresponding to the application program with the exception and corresponding equipment information of the equipment with the exception, thereby generating data to be reported, performing matching configuration on exception processing configuration information in exception processing configuration and exception information, namely executing the step 303, inquiring whether the data are matched, if the data are matched, obtaining a configuration result, namely the matched exception processing operation, checking whether exception protection is performed in the exception processing operation, if so, performing protection, obtaining reported data according to the protection result and the exception data, reporting the reported data to a server, wherein the exception data is the data to be reported, the protection result is determined according to whether the application program can normally run, if the application program normally runs, if the protection result is that the protection is successful, and if the application program is crashed, the protection result is that the protection is failed; if the data are not matched or the abnormal protection is not carried out, namely if the data are matched or the output of the judgment box for the abnormal protection is negative, reporting the reported data to the server according to the abnormal data and the abnormal processing result, namely if the abnormal protection is not carried out, and at the moment, collapsing the application program; after the reported data are transmitted to the server, the server can store the reported data in the database and count the reported data.
In the exception handling process in this embodiment, the application information corresponding to the application program that has the exception and the device information corresponding to the electronic device that has the exception, which are included in the exception environment information, may be reported to the server, so that the server may perform statistics according to the reported data, and display the statistical result, thereby facilitating the developers to adjust the exception configuration data, analyze the exception protection processing, and adjust and update the exception configuration file according to the exception handling effect.
The steps of the above methods are divided for clarity, and the implementation may be combined into one step or split some steps, and the steps are divided into multiple steps, so long as the same logical relationship is included, which are all within the protection scope of the present patent; it is within the scope of the patent to add insignificant modifications to the algorithms or processes or to introduce insignificant design changes to the core design without changing the algorithms or processes.
A third embodiment of the present invention relates to an exception handling apparatus, as shown in fig. 5, including: an interception module 501, configured to intercept an exception message that is reported to an operating system and is triggered when a code exception occurs in an operating process of an application; an exception handling operation obtaining module 502, configured to obtain the abnormal exception information according to the exception message, and query, in exception handling configuration information, an exception handling operation matched with the exception information; the exception handling configuration information comprises a corresponding relation between exception information and exception handling operation; the exception handling module 503 is configured to, if a matching exception handling operation is found, execute the matching exception handling operation.
The exception handling operation obtaining module 502 is further configured to query, in the exception configuration information, a configuration item that matches environment information where the code exception occurs and a reason of the code exception occurrence, and use a code exception handling operation included in the queried configuration item as the matched exception handling operation, where the exception information includes: environmental information of the occurrence of the code exception and a reason of the occurrence of the code exception; the exception handling configuration information includes a plurality of configuration items, each of which includes an exception handling operation, environmental information, and an exception cause.
The exception handling module 503 is further configured to perform forced interrupt of the application program process operation on the process generating the code exception when no matching exception handling operation is found.
The exception handling module 503 is further configured to, after the performing the matched exception handling operation or after the performing the operation of forcibly interrupting the application program process, further include: acquiring an exception handling result for handling the code exception; determining reported data according to the classification result of the code exception and the exception handling result; wherein the classification result is determined according to the abnormal information; and sending the reported data to a server so that the server can count the reported data to obtain a statistical result of abnormal processing.
The interception module 501 is further configured to register an exception snoop, where the exception snoop is configured to snoop the exception message; the exception message carries a semaphore used for acquiring exception stack information; and replacing the operation of forcibly interrupting the application program process in the operating system with the exception handling operation.
The interception module 501 is further configured to locally query the abnormal configuration data of the application program, or request the abnormal configuration data of the application program from a server; and analyzing the abnormal configuration data to obtain the abnormal processing configuration information.
The intercepting module 501 is further configured to, if the server requests the abnormal configuration data of the application program, carry, in the abnormal configuration data request for requesting the abnormal configuration data, the digest information of the abnormal configuration data corresponding to the abnormal processing configuration information of the application program, which is obtained through analysis, so that the server determines whether an updated version of the abnormal processing configuration information exists, and feeds back the updated version after determining that the updated version exists.
Exceptions to the program code in the exception handling operation acquisition module 502 include any one of, and combinations of: the non-main thread is abnormal, the user interface is abnormal, and the array is abnormal when the array is out of bounds: when the code exception is a non-main thread exception, the exception handling operation is a thread with an interrupt exception; when the code exception is that the user interface is abnormal, the exception handling operation is to close the exception interface; and when the program code exception is an array out-of-range exception, the exception handling operation is to return interpolation.
It should be understood that the present embodiment is a system embodiment corresponding to the first embodiment, and the present embodiment can be implemented in cooperation with the first embodiment. The related technical details mentioned in the first embodiment are still valid in this embodiment, and are not described herein again in order to reduce repetition. Accordingly, the related-art details mentioned in the present embodiment can also be applied to the first embodiment.
It should be noted that, all the modules involved in this embodiment are logic modules, and in practical application, one logic unit may be one physical unit, may also be a part of one physical unit, and may also be implemented by a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, a unit which is not so closely related to solve the technical problem proposed by the present invention is not introduced in the present embodiment, but this does not indicate that there is no other unit in the present embodiment.
A fourth embodiment of the invention relates to an electronic device, as shown in fig. 6, comprising at least one processor 601; and a memory 602 communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the above-described exception handling method.
Where the memory and processor are connected by a bus, the bus may comprise any number of interconnected buses and bridges, the buses connecting together one or more of the various circuits of the processor and the memory. The bus may also connect various other circuits such as peripherals, voltage regulators, power management circuits, and the like, which are well known in the art, and therefore, will not be described any further herein. A bus interface provides an interface between the bus and the transceiver. The transceiver may be one element or a plurality of elements, such as a plurality of receivers and transmitters, providing a means for communicating with various other apparatus over a transmission medium. The data processed by the processor is transmitted over a wireless medium via an antenna, which further receives the data and transmits the data to the processor.
The processor is responsible for managing the bus and general processing and may also provide various functions including timing, peripheral interfaces, voltage regulation, power management, and other control functions. And the memory may be used to store data used by the processor in performing operations.
A fifth embodiment of the present invention relates to a computer-readable storage medium storing a computer program. The computer program realizes the above-described method embodiments when executed by a processor.
That is, as can be understood by those skilled in the art, all or part of the steps in the method for implementing the embodiments described above may be implemented by a program instructing related hardware, where the program is stored in a storage medium and includes several instructions to enable a device (which may be a single chip, a chip, or the like) or a processor (processor) to execute all or part of the steps of the method described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It will be understood by those of ordinary skill in the art that the foregoing embodiments are specific embodiments for practicing the invention, and that various changes in form and details may be made therein without departing from the spirit and scope of the invention in practice.

Claims (10)

1. An exception handling method, comprising:
intercepting an abnormal message which is triggered when a code is abnormal in the running process of an application program and is reported to an operating system;
acquiring abnormal information of the code abnormality according to the abnormal information, and inquiring abnormal processing operation matched with the abnormal information in abnormal processing configuration information; the exception handling configuration information comprises a corresponding relation between exception information and exception handling operation;
and if the matched exception handling operation is inquired, executing the matched exception handling operation.
2. The exception handling method according to claim 1, wherein said exception information comprises: environmental information of the occurrence of the code exception and a reason of the occurrence of the code exception; the exception handling configuration information comprises a plurality of configuration items, and each configuration item comprises exception handling operation, environment information and an exception reason;
the querying, in the exception handling configuration information, the exception handling operation matched with the exception information includes:
and inquiring configuration items matched with the environment information of the code exception and the reason of the code exception in the exception configuration information, and taking exception handling operation included in the inquired configuration items as the matched exception handling operation.
3. The exception handling method according to claim 1, wherein after querying the exception handling configuration information for the exception handling operation matching the exception information, further comprising:
and if the matched exception handling operation is not inquired, performing forced interrupt application program process operation on the process generating the code exception.
4. The exception handling method according to claim 3, further comprising, after said performing said matched exception handling operation or after said performing an interrupt-forced application process operation:
acquiring an exception handling result for handling the code exception;
determining reported data according to the classification result of the code exception and the exception handling result; wherein the classification result is determined according to the abnormal information;
and sending the reported data to a server so that the server can count the reported data to obtain a statistical result of abnormal processing.
5. The exception handling method according to any one of claims 1 to 4, wherein before intercepting an exception message that is reported to an operating system and is triggered when a code exception occurs during a running process, the method further includes:
registering abnormal monitoring, wherein the abnormal monitoring is used for monitoring the abnormal message; the exception message carries a semaphore used for acquiring stack information of code exception;
and replacing the operation of forcibly interrupting the application program process in the operating system with the exception handling operation.
6. The exception handling method according to any one of claims 1 to 4, wherein before intercepting an exception message that is reported to an operating system and is triggered when a code exception occurs during a running process, the method further includes:
locally inquiring abnormal configuration data of the application program, or requesting the abnormal configuration data of the application program from a server;
and analyzing the abnormal configuration data to obtain the abnormal processing configuration information.
7. The exception handling method according to claim 6, wherein if the server requests the server for the exception configuration data of the application program, in the sent exception configuration data request for requesting the exception configuration data, summary information of the exception configuration data corresponding to the exception configuration information of the application program obtained through analysis is carried, so that the server determines whether an updated version of the exception configuration information exists, and feeds back the updated version after determining that the updated version exists.
8. The exception handling method according to any one of claims 1 to 4 wherein the code exception comprises any one of, and combinations of: the non-main thread is abnormal, the user interface is abnormal, and the array is abnormal when the array is out of bounds:
when the code exception is a non-main thread exception, the exception handling operation is to interrupt the thread with exception;
when the code exception is that the user interface is abnormal, the exception handling operation is to close the exception interface;
and when the code exception is an array out-of-range exception, the exception handling operation is returning interpolation.
9. An electronic device, comprising:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the exception handling method of any one of claims 1 to 8.
10. A computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the exception handling method of any one of claims 1 to 8.
CN202110009427.8A 2021-01-05 2021-01-05 Exception handling method, electronic device, and storage medium Pending CN112698980A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110009427.8A CN112698980A (en) 2021-01-05 2021-01-05 Exception handling method, electronic device, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110009427.8A CN112698980A (en) 2021-01-05 2021-01-05 Exception handling method, electronic device, and storage medium

Publications (1)

Publication Number Publication Date
CN112698980A true CN112698980A (en) 2021-04-23

Family

ID=75514800

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110009427.8A Pending CN112698980A (en) 2021-01-05 2021-01-05 Exception handling method, electronic device, and storage medium

Country Status (1)

Country Link
CN (1) CN112698980A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023005459A1 (en) * 2021-07-29 2023-02-02 Oppo广东移动通信有限公司 Exception handling method and apparatus, computer device, and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8239836B1 (en) * 2008-03-07 2012-08-07 The Regents Of The University Of California Multi-variant parallel program execution to detect malicious code injection
CN108304447A (en) * 2017-12-07 2018-07-20 北京趣拿软件科技有限公司 Processing method, device, storage medium and the processor of exception information
CN111708655A (en) * 2020-06-19 2020-09-25 北京达佳互联信息技术有限公司 Application crash processing method, device and system
CN112052185A (en) * 2020-09-29 2020-12-08 北京百度网讯科技有限公司 Applet exception handling method and device, electronic device and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8239836B1 (en) * 2008-03-07 2012-08-07 The Regents Of The University Of California Multi-variant parallel program execution to detect malicious code injection
CN108304447A (en) * 2017-12-07 2018-07-20 北京趣拿软件科技有限公司 Processing method, device, storage medium and the processor of exception information
CN111708655A (en) * 2020-06-19 2020-09-25 北京达佳互联信息技术有限公司 Application crash processing method, device and system
CN112052185A (en) * 2020-09-29 2020-12-08 北京百度网讯科技有限公司 Applet exception handling method and device, electronic device and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023005459A1 (en) * 2021-07-29 2023-02-02 Oppo广东移动通信有限公司 Exception handling method and apparatus, computer device, and storage medium

Similar Documents

Publication Publication Date Title
US7984334B2 (en) Call-stack pattern matching for problem resolution within software
US7266726B1 (en) Methods and apparatus for event logging in an information network
US7284238B2 (en) Multithread tracing method and apparatus
CN101788949B (en) Method and device for realizing embedded type system function monitoring
CN109542718B (en) Service call monitoring method and device, storage medium and server
KR20180037342A (en) Application software error monitoring, statistics management service and solution method.
US20230046979A1 (en) Microservice call method and apparatus, device, and medium
CN111381940B (en) Distributed data processing method and device
CN101599113A (en) Driven malware defence method and device
CN112306833A (en) Application program crash statistical method and device, computer equipment and storage medium
CN112698980A (en) Exception handling method, electronic device, and storage medium
CN112948255B (en) Distributed kernel fuzzy test system and method
CN113342849B (en) Data auditing method and device, electronic equipment and storage medium
CN108268266A (en) A kind of upgrade method and device
CN111752838A (en) Question checking method and device, server and storage medium
US10061681B2 (en) System for discovering bugs using interval algebra query language
CN110231921B (en) Log printing method, device, equipment and computer readable storage medium
US7363615B2 (en) Stack-based callbacks for diagnostic data generation
CN110990179A (en) Task processing method, device and equipment
CN115080507A (en) Vehicle fault snapshot data storage method, system, equipment and storage medium
US20230097449A1 (en) Method and system for intercepting dirty data
CN112214437A (en) Storage device, communication method and device and computer readable storage medium
CN116932274B (en) Heterogeneous computing system and server system
CN113761015B (en) Log processing method, device, system and storage medium
CN112486755B (en) Server detection method, detection device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination