CN116126735A - Code exception handling method, device, equipment and storage medium - Google Patents

Code exception handling method, device, equipment and storage medium Download PDF

Info

Publication number
CN116126735A
CN116126735A CN202310392270.0A CN202310392270A CN116126735A CN 116126735 A CN116126735 A CN 116126735A CN 202310392270 A CN202310392270 A CN 202310392270A CN 116126735 A CN116126735 A CN 116126735A
Authority
CN
China
Prior art keywords
code
code block
exception
exception handling
interface address
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.)
Granted
Application number
CN202310392270.0A
Other languages
Chinese (zh)
Other versions
CN116126735B (en
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.)
Ziguang Tongxin Microelectronics Co Ltd
Original Assignee
Ziguang Tongxin Microelectronics 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 Ziguang Tongxin Microelectronics Co Ltd filed Critical Ziguang Tongxin Microelectronics Co Ltd
Priority to CN202310392270.0A priority Critical patent/CN116126735B/en
Publication of CN116126735A publication Critical patent/CN116126735A/en
Application granted granted Critical
Publication of CN116126735B publication Critical patent/CN116126735B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3644Software debugging by instrumenting at runtime
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3692Test management for test results analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Advance Control (AREA)

Abstract

The application provides a method, a device, equipment and a storage medium for processing code exception, which are applied to the field of program exception processing. Comprising the following steps: executing the first code block, determining a first interface address according to a first exception monitoring code statement in the first code block, pushing the first interface address into an exception handling stack, and calling the first exception handling code block to perform exception handling according to the first interface address when the first code block is executed to have an exception. Thus, the interface address of the calling processing exception code block is pushed into the exception processing stack, so that the exception processing code block and the code block are stored separately, the exception processing code is prevented from being programmed into the program code, and the code quantity in the program code is reduced. When an abnormality occurs in the execution process of the code block, the abnormality processing code block can be directly called according to the interface address in the abnormality processing stack to process the abnormality; if no exception occurs in the execution process of the code block, the exception processing code block is not required to be called, and only the code statement in the code block is executed.

Description

Code exception handling method, device, equipment and storage medium
Technical Field
The present disclosure relates to the field of program exception processing technologies, and in particular, to a method, an apparatus, a device, and a storage medium for processing code exception.
Background
In the computer arts, a computer program is a set of instructions that can be recognized and executed by a computer, running on the computer. One of the requirements of computer program code design is to ensure the robustness of the program code, and it is desirable that the program code be able to run without or with fewer problems during execution. When a problem occurs in the process of executing the program code, namely, an abnormality occurs, the program may crash, and the system cannot normally run. In order to protect the smooth execution of program code, the stability of system operation generally requires designing the related code for exception handling during the development of the program code.
In the related art, a specific keyword is designed in a programming language, a code for an exception is designed by using the keyword, and then a code for monitoring and processing the exception is programmed into a program code, for example, in the process of programming and developing, a statement for monitoring the exception or processing the exception is written in the program code of an interface function, so that the monitoring and processing of the exception in the process of executing the program is realized. However, the method can code exception monitoring or exception handling in the original program code, and the exception handling position and type table are generated by counting all exception handling in the compiling stage, so that the code or byte code quantity of the program is overlarge.
Disclosure of Invention
In view of this, the embodiments of the present application provide a method, an apparatus, a device, and a storage medium for processing code exceptions, which aim to write and store exception processing codes dispersed in program codes in a unified manner, and simplify the program codes.
In a first aspect, an embodiment of the present application provides a method for processing a program exception based on a stack, where the method includes:
executing a first code block, wherein the first code block is a group of code sentences;
determining a first interface address corresponding to a first exception handling code block for handling exceptions in the execution process of the first application program code according to a first exception monitoring code statement in the first code block;
pushing the first interface address into an exception handling stack, wherein the exception handling stack is used for storing the interface address corresponding to the exception handling code block;
when an exception occurs in the execution process of the first code block, popping the first interface address from the exception handling stack;
and calling the first exception handling code block according to the first interface address to perform exception handling.
Optionally, the first code block includes invoking a second code block code statement, and the method further includes:
and calling the second code block according to the code statement of the second code block.
Optionally, the second code block includes a second exception monitor code statement, and the calling the second code block includes:
determining a second interface address corresponding to a second exception handling code block for handling exceptions in the execution process of the second code block according to the second exception monitoring code statement;
pushing the second interface address to the exception handling stack.
Optionally, the second code block does not include a second exception monitor code statement, and the calling the second code block includes:
when an exception occurs in the execution process of the second code block, popping the first interface address from the exception handling stack;
and calling the first exception handling code block according to the first interface address to perform exception handling.
Optionally, the calling the second code block includes:
when an exception occurs in the execution process of the second code block, popping the second interface address from the exception handling stack;
and calling the second code block to perform exception handling according to the second interface address.
Optionally, the first exception monitoring code statement is not included in the first code block, and the method further includes:
and when an abnormality occurs in the execution process of the first code block, calling a preset abnormality processing code block to perform abnormality processing.
Optionally, the method further comprises:
and after the exception handling is completed, continuing to execute the code blocks according to the exception handling result.
In a second aspect, an embodiment of the present application provides a stack-based program exception handling apparatus, where the apparatus includes:
the execution module is used for executing a first code block, wherein the first code block is a group of code sentences;
the determining module is used for determining a first interface address corresponding to a first exception handling code block for handling exceptions in the execution process of the first application program code according to a first exception monitoring code statement in the first code block;
the pushing module is used for pushing the first interface address into an exception handling stack, and the exception handling stack is used for storing the interface address corresponding to the exception handling code block;
the pop-up module is used for popping up the first interface address from the exception handling stack when an exception occurs in the execution process of the first code block;
and the processing module is used for calling the first exception handling code block according to the first interface address to perform exception handling.
Optionally, the first code block includes invoking a second code block code statement, and the apparatus further includes:
and the calling module is used for calling the second code block according to the code statement of the second code block.
Optionally, the second code block includes a second exception monitoring code statement, and the calling module is specifically configured to:
determining a second interface address corresponding to a second exception handling code block for handling exceptions in the execution process of the second code block according to the second exception monitoring code statement;
pushing the second interface address to the exception handling stack.
Optionally, the second code block does not include a second exception monitoring code statement, and the calling module is specifically configured to include:
when an exception occurs in the execution process of the second code block, popping the first interface address from the exception handling stack;
and calling the first exception handling code block according to the first interface address to perform exception handling.
Optionally, the calling module is specifically configured to:
when an exception occurs in the execution process of the second code block, popping the second interface address from the exception handling stack;
and calling the second code block to perform exception handling according to the second interface address.
Optionally, the first exception monitoring code statement is not included in the first code block, and the apparatus further includes:
and the protection module is used for calling a preset exception handling code block to perform exception handling when an exception occurs in the execution process of the first code block.
Optionally, the apparatus further includes:
and the recovery module is used for continuing to execute the code blocks according to the exception handling result after the exception handling is completed.
In a third aspect, embodiments of the present application provide an apparatus, the apparatus including a memory for storing instructions or code, and a processor for executing the instructions or code to cause the apparatus to perform the method for processing a code exception of any one of the preceding first aspects.
In a fourth aspect, embodiments of the present application provide a computer storage medium having code stored therein, where when the code is executed, an apparatus executing the code implements the method for processing a code exception of any one of the foregoing first aspects.
The embodiment of the application provides a method, a device, equipment and a storage medium for processing code exception. When the method is executed, a first code block is executed first, a first interface address is determined according to a first abnormal monitoring code statement in the first code block, and then the first interface address is pushed into an abnormal processing stack; then, when an abnormality occurs in the execution process of the first code block, the first interface address is popped up from the abnormality processing stack; and finally, calling a first exception handling code block to handle the exception according to the first interface address so as to complete exception handling. Thus, by storing the exception handling code block separately from the code block, the encoding of the exception handling code into the program code is avoided, and the amount of code in the program code can be reduced. When an abnormality occurs in the execution process of the program code, the abnormality processing code block can be directly called from an interface address in an abnormality processing stack, so that the abnormality occurring in the execution process of the program code is processed; if no exception occurs in the execution process of the program code, the exception processing code block is not required to be called, and only the code statement in the code block is executed. And the exception handling codes scattered in the program codes are uniformly written and stored, so that the effect of simplifying the program codes is achieved. In this way, the amount of code in the program code can be reduced.
Drawings
In order to more clearly illustrate the present embodiments or the technical solutions in the prior art, the drawings that are required for the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a method for processing code exceptions according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a code block according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a program module according to an embodiment of the present application;
fig. 4 is a schematic diagram of a first code block provided in an embodiment of the present application;
FIG. 5 is a schematic diagram of an exception handling stack according to an embodiment of the present disclosure;
FIG. 6 is a schematic diagram of a first exception handling procedure according to an embodiment of the present application;
FIG. 7 is a schematic diagram of a resume execution code block according to an embodiment of the present application;
FIG. 8 is a schematic diagram of a code block calling other code blocks according to an embodiment of the present application;
FIG. 9 is a schematic diagram of invoking a second code block according to an embodiment of the present application;
FIG. 10 is a schematic diagram of another exception handling stack according to an embodiment of the present application;
FIG. 11 is a schematic diagram of a second type of code exception handling according to an embodiment of the present disclosure;
FIG. 12 is a schematic diagram of a third code exception handling provided in an embodiment of the present application;
FIG. 13 is a schematic diagram of fourth code exception handling according to an embodiment of the present disclosure;
FIG. 14 is a schematic diagram of an anomaly type identifier according to an embodiment of the present application;
FIG. 15 is a schematic diagram of a computer implemented code exception handling provided in an embodiment of the present application;
fig. 16 is a schematic structural diagram of a device for processing code exceptions according to an embodiment of the present application.
Detailed Description
In the field of computer technology, when an application program code is executed, an exception is found by a virtual machine or a running environment, and the program data error is generally classified into a common exception and a fatal exception, wherein the common exception does not destroy the data and the flow of the program execution, but the fatal exception may cause program crash, so that in order to protect the smooth execution of the current program, the exception generated in the execution process is usually required to be processed, and then the subsequent running flow of the application program is determined according to the processing.
In the related art, by adding keywords in a programming language, and constructing exception handling mechanisms such as try, catch, and finaly based on the keywords. the try part is used for determining the code range of the abnormality to be monitored, the compound sentences behind the try are called protected segments, and the code of the protected segments is likely to be abnormal, so that the abnormality detection is carried out on the try part. The catch part is responsible for processing the exception generated in the try monitoring range, is used for capturing the exception and processing the exception, no exception is generated, the code does not need to be executed, and an 'exception type' is specified in a bracket behind each catch, so that the code can capture which type of exception. Once the exception is captured, processing is performed by the exception handling statement. The final portion is used to execute a given statement, and this portion of code is executed whether or not an exception is raised, and whether or not an exception is required to be handled. In programming languages, keywords for anomalies need to be paired up, such as: try and catch pair are used, try and finall pair are used, or try, multiple catches and finall are used together. However, the exception handling statement or the exception handling code block is often quite complex, and there are cases where the same exception handling statement or exception handling code block needs to be repeated a plurality of times in the application program, which greatly increases the code amount of the application program, and the structure of the code also becomes complex, so that the operating pressure of the computer increases.
In view of the above technical problems, according to the stack-based program exception handling method provided by the present application, by storing an exception handling code block separately from an executed code block and storing an interface address corresponding to the exception handling code block in an exception handling stack, the amount of code in program code can be reduced. When an abnormality occurs in the execution process of the program code, a corresponding abnormality processing code block can be directly called according to an interface address in an abnormality processing stack, and the abnormality occurring in the execution process of the program code is processed by utilizing the abnormality processing code block; if no abnormality occurs in the execution process of the application program, the abnormal processing code block is not required to be called, the executed code quantity is reduced, and the program logic is simplified. The exception handling codes scattered in the program codes are uniformly stored, so that the effect of simplifying the program codes is achieved. In addition, although the exception handling code block codes and the application program codes in the exception handling stack have respective operation stacks, the exception handling stacks do not exist independently and can be used as an additional part of the application program to be in an operation environment, when the execution of the application program is abnormal, a computer can inquire an interface address and call the exception handling code blocks, and the code space in the application program is saved.
It will be apparent that the described embodiments are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
Referring to fig. 1, fig. 1 is a flowchart of a method for processing code exception according to an embodiment of the present application, including:
s101: the first code block is executed.
The first code is a set of code statements, it being understood that other code blocks in the present application are also made up of a set of code statements. Referring to fig. 2, fig. 2 is a schematic diagram of a code block provided in an embodiment of the present application. In fig. 2, the code statements in the code blocks are sequentially arranged, and of course, when executing the code blocks, the code statements should be sequentially executed according to the arrangement order of the code statements, and in the embodiment of the present application, the number n (n is greater than or equal to 1) of the code statements in the code blocks and the arrangement order of the code statements are not limited, and may be set as required.
In this embodiment of the present application, the first code block may be stored in the program module together with other code blocks and the exception handling code block, and the computer directly calls the first code block from the program module when executing step S101. Referring specifically to fig. 3, fig. 3 is a schematic diagram of a program module according to an embodiment of the present application.
S102: and determining a first interface address corresponding to a first exception handling code block for handling exceptions in the execution process of the first application program code according to the first exception monitoring code statement in the first code block.
The first exception handling code block is used for handling exceptions occurring during execution of the first code block. The first interface address is an address of an interface for calling the first exception handling code block. The first exception monitor code statement is for indicating an exception handling method with the first exception handling code block as the first code block and setting an exception monitor state. The exception monitoring scope is the next code statement of the first exception monitoring code statement to function exit. As an example, the first exception monitor code statement may be "pushException (void) method_2", and "method_2" is the first exception handling code block. Referring to fig. 4, fig. 4 is a schematic diagram of a first code block provided in an embodiment of the present application.
The interface address corresponding to the abnormal processing code block for processing the abnormality occurring in the execution process of the first code block, namely the first interface address corresponding to the first abnormal processing code block, can be determined through the first abnormal monitoring code statement.
S103: the first interface address is pushed to an exception handling stack.
The exception handling stack is used for storing interface addresses corresponding to the exception handling code blocks. Referring to fig. 5, fig. 5 is a schematic diagram of an exception handling stack according to an embodiment of the present application. After determining a first interface address corresponding to the first exception handling code block according to the first exception monitoring code statement, pushing the first interface address into an exception handling stack, and performing exception capturing processing on the first code block in the execution process.
Stacks (stacks), also known as stacks, are a type of linear table that is operation constrained. A linear table is defined in which insert and delete operations are performed only at the end of the table. One end for insertion or deletion is called the top of the stack, and the other end is called the bottom of the stack. Inserting a new element into a stack, also called pushing, pushing or pressing, and placing the new element onto the top element to make the new element a new top element; deleting an element from a stack, also known as popping or popping, deletes the top element, and causes the elements adjacent to the deleted top element to become new top elements. Thus, pushing the first interface address into the exception handling stack essentially pushes the first interface address onto the top of the exception handling stack.
In this embodiment of the present application, the exception handling stack does not exist independently, and may be used as an additional part of an application program in one running environment, that is, two stacks exist in the same running environment at the same time, where one stack is an exception handling stack, and the other stack is a running stack of a code block. When the program code execution is abnormal, the computer can query the interface address to call the abnormal processing code block corresponding to the interface address by using the abnormal processing stack.
S104: when an exception occurs in the execution process of the first code block, the first interface address is popped from the exception handling stack.
When an exception occurs in the execution process of the first code block, the first interface address corresponding to the first exception handling code block pushed in step S103 is correspondingly popped from the exception handling stack. Referring to fig. 6, fig. 6 is a schematic diagram of first exception handling of a program according to an embodiment of the present application. Taking fig. 6 as an example, when an exception occurs in the execution process of the first code block, the exception is thrown, and the first interface address is popped from the exception handling stack to call the first exception handling code block.
S105: and calling the first exception handling code block according to the first interface address to perform exception handling.
Referring to fig. 6, after the first interface address is popped up, the first exception handling code block is called according to the first interface address, so that the first exception handling code block is executed to handle an exception occurring during the execution of the first code block.
In one possible implementation, the method further includes:
and after the exception processing is completed, continuing to execute the code blocks according to the exception processing result.
After the exception processing is completed, the exception processing interface corresponding to the exception processing code block returns an exception processing result. The exception handling results may be represented by characters, such as 0, 1, and 2. And judging the level to which rollback is required according to the exception handling result. For example, if the exception result is 0, the execution of the next code statement in the code block with the exception is continued, and if the exception result is a non-0 character, the non-0 character represents a level to be rolled back, that is, the next code statement with the exception thrown out in the code block corresponding to the level is rolled back upwards according to the function call level recorded in the function call stack. Wherein the function call stack is the stack required for the code block to run.
For example: the second code block is called in the code statement of the first code block, the third code block is called in the code statement of the second code block, and an exception occurs in the execution process of the third code block. After the exception processing is completed, if the returned exception processing result is 0, returning to the code statement of the third code block to throw out the next code statement of the exception; if the returned exception handling result is 1, the next code statement of the third code block is called in the code statements of the second code block, and if the returned exception handling result is 2, the next code statement of the second code block is called in the code statements of the first code block. If the return value of the exception handling result is greater than the function call hierarchy, the execution code block is exited.
Referring to fig. 7, fig. 7 is a schematic diagram of a restoration execution code block provided in an embodiment of the present application. And after the first exception handling code block is executed to handle the exception occurring in the execution process of the first code block, returning to the exception handling result of 0, and continuing to execute the next code statement 4 of the first code block, which throws out the exception code statement.
The embodiment of the application provides a method, a device, equipment and a storage medium for processing code exception. When the method is executed, a first code block is executed first, a first interface address is determined according to a first abnormal monitoring code statement in the first code block, and then the first interface address is pushed into an abnormal processing stack; then, when an abnormality occurs in the execution process of the first code block, the first interface address is popped up from the abnormality processing stack; and finally, calling a first exception handling code block to handle the exception according to the first interface address so as to complete exception handling. Thus, by storing the exception handling code block separately from the code block, the encoding of the exception handling code into the program code is avoided, and the amount of code in the program code can be reduced. When an abnormality occurs in the execution process of the program code, the abnormality processing code block can be directly called from an interface address in an abnormality processing stack, so that the abnormality occurring in the execution process of the program code is processed; if no exception occurs in the execution process of the program code, the exception processing code block is not required to be called, and only the code statement in the code block is executed. And the exception handling codes scattered in the program codes are uniformly written and stored, so that the effect of simplifying the program codes is achieved. In this way, the amount of code in the program code can be reduced.
In the program code, there is a case that code blocks call each other, for which the application provides an embodiment, the first code block includes a code statement that calls the second code block, and the method further includes:
and calling the second code block according to the code statement of the second code block.
Referring to fig. 8, fig. 8 is a schematic diagram of calling other code blocks by a code block according to an embodiment of the present application. The first code block comprises a second code block statement, and the second code block is called when the second code block statement is called according to the arrangement sequence of the code statements. It will be appreciated that when the second code block call is completed, an exception result is returned (in this embodiment, the exception result is taken as 0 as an example), and the next code statement 4 in the first code block that calls the second code block code statement is returned according to the exception result.
In the above, the application program is composed of a set of code statements, and the second code block may also include a second exception monitor code statement, as in the first code block. Based on the first code block including the call to the second code block code statement, the present application provides two embodiments including the second exception monitor code statement and not including the second exception monitor code statement in the second code block.
In one embodiment provided herein, the second code block includes a second exception monitor code statement, and the invoking the second code block includes:
determining a second interface address corresponding to a second exception handling code block for handling exceptions in the execution process of the second code block according to the second exception monitoring code statement;
pushing the second interface address to the exception handling stack.
Referring to fig. 9, fig. 9 is a schematic diagram of invoking a second code block according to an embodiment of the present application. As shown in fig. 9, a second exception monitor code statement is included in the second code block. The second exception handling code block is used for handling exceptions occurring during execution of the second code block. The second interface address is an address of an interface for calling the second exception handling code block. The second exception monitoring code statement is used for indicating a second exception handling code block as an exception handling method of the second code block and setting an exception monitoring state. The exception monitoring scope is the next code statement of the second exception monitoring code statement to function exit. When the second exception monitoring code statement is executed, an interface address corresponding to an exception handling code block for handling an exception occurring in execution of the second code block, that is, a second interface address corresponding to the second exception handling code block, can be determined. As an example, the second exception monitor code statement may be "pushException (void) method_3", and "method_3" is the second exception handling code block. And pushing the second interface address into the exception handling stack after determining the second interface address corresponding to the second exception handling code block. Referring to fig. 10, fig. 10 is a schematic diagram of another exception handling stack according to an embodiment of the present application. As shown in fig. 10, after pushing the second interface address corresponding to the second exception handling code block to the stack top of the exception handling stack, the first interface address is located at the stack bottom, and the second interface address is located at the stack top.
In the case where the second code block includes a second exception monitor code statement, when an exception occurs during execution of the second application, the second exception handling code block may be utilized for processing. In one possible implementation manner provided in the present application, the calling the second code block includes:
when an exception occurs in the execution process of the second code block, popping the second interface address from the exception handling stack;
and calling the second code block to perform exception handling according to the second interface address.
Referring to fig. 11, fig. 11 is a schematic diagram of a second type of code exception handling according to an embodiment of the present application. As shown in fig. 11, the solid line indicates the execution of the code block, and the broken line indicates the execution of the processing of the abnormality by the abnormality processing code block when the abnormality occurs. And when the second code block is abnormal in the execution process, throwing the abnormality, popping a second interface address from the stack top of the abnormality processing stack, and calling the second abnormality processing code block to process the abnormality according to the second interface address. And, after the execution of the second exception handling code block processes the exception occurring in the execution process of the second code block, returning an exception handling result (in this embodiment, the exception handling result is taken as 0 as an example), and returning to execute the next code statement 3 of the second code block, from which the exception code statement is thrown, according to the exception handling result, to continue to execute the second code block.
In some cases, there may be an abnormal situation in the process of executing the second exception handling code block to handle the exception, and the application provides an embodiment, when the second exception handling code block is abnormal in the process of executing the second exception handling code block, the exception is thrown out, a first interface address is popped from the stack top of the exception handling stack, and the exception handling that occurs in the process of executing the second exception handling code block is performed according to the first interface address.
Referring to fig. 12, fig. 12 is a schematic diagram of third code exception handling according to an embodiment of the present application. As shown in fig. 12, the solid line indicates the execution of the code block, and the broken line indicates the execution of the processing of the exception by the exception processing code block when the exception occurs. When an exception occurs or the exception is serious and cannot be handled in the process of executing the second exception handling code block to handle the exception, the interface address needs to be continuously popped from the exception handling stack, and when the exception occurs in the process of processing the second code block to execute, the second interface address is popped from the stack top of the exception handling stack, and the stack top of the current exception handling stack is the first interface address, as shown in fig. 5. And popping up a first interface address from the stack top of the exception handling stack, and calling a first exception handling code block according to the first interface address to handle exceptions occurring in the execution process of a second exception handling code block.
By storing the interface address corresponding to the exception handling code block in the exception handling stack, when an exception occurs in the code block or the execution of the exception handling code block, the interface address of the previous level can be called from the exception handling stack. In addition, the interface addresses in the exception handling stack are pushed to the top of the stack in order of logic, so that the interface addresses can be popped out in order.
Also, in the related art, if a certain exception handling code block is repeatedly executed, it is necessary to repeatedly write the exception handling code block into the code block. By the method provided by the application, the exception handling can be realized without repeatedly writing the exception handling code blocks into the code blocks and uniformly storing the interface addresses corresponding to the exception handling code blocks in the exception handling stack.
In another embodiment provided in the present application, the second code block does not include a second exception monitor code statement, and the calling the second code block includes:
when an exception occurs in the execution process of the second code block, popping the first interface address from the exception handling stack;
and calling the first exception handling code block according to the first interface address to perform exception handling.
Referring to fig. 13, fig. 13 is a schematic diagram of fourth code exception handling according to an embodiment of the present application. As shown in fig. 13, the solid line indicates the execution of the code block, and the broken line indicates the execution of the processing of the abnormality by the abnormality processing code block when the abnormality occurs. In this embodiment of the present application, if the exception handling method used by the second code block is the same as the exception handling method used by the first code block, the second exception monitoring code statement does not need to be set in the second code block, and the storage state of the exception handling stack is shown in fig. 5. When an abnormality occurs in the execution process of the second code block, a first interface address corresponding to the first abnormality processing code block is popped up from the stack top of the abnormality processing stack, and the first abnormality processing code block is called according to the first interface address to process the abnormality occurring in the execution process of the second code block.
According to the code exception handling method, exception monitoring and handling can be achieved without using keywords aiming at exceptions, and exception handling is conducted on program codes based on stacks in a programming language environment which does not support an exception handling mechanism, so that control of code operation exception flow can be achieved, data or operation environment exceptions can be handled, and exception handling requirements are met. Compared with a programming language environment supporting an exception handling mechanism in the related art, by the method provided by the embodiment of the application, the interface addresses corresponding to the exception handling codes scattered in the program codes are uniformly stored in the exception handling stack, so that the application program codes are simplified, and the code space overhead is saved.
The embodiment of the application also provides a schematic diagram of the anomaly type identifier. As shown in FIG. 14, the exception type identifier has 16 bits in total, numbered sequentially from right to left, bits 0-7 are the exception number, bits 8-13 are the module number, and bits 14-15 are the special flags. Wherein the special flags include two cases: when the 14 th bit to the 15 th bit are all 1, the exception is represented to be of a common exception type, not of an ISO exception type; when bits 14-15 are not all 1, it is represented that the exception is of the ISO exception type. The type of the abnormality can be determined by the abnormality type identification, and which type of abnormality is thrown by which module can be identified at the time of abnormality processing.
For ease of understanding, the execution flow of the program will be described in detail below in conjunction with a computer device. Referring to fig. 15, fig. 15 is a schematic diagram of a computer implemented code exception handling according to an embodiment of the present application.
S1501: executing the first code block, and executing the first code block piece by piece according to the code statement of the first code block.
S1502: and setting a calling interface corresponding to the first exception handling code block at an interface of calling the running environment at the place where the exception monitoring is required to be set, and starting an exception handling mechanism.
S1503: pushing a first interface address corresponding to the first exception handling code block into an exception handling stack to serve as an exception handling method of the first code block.
S1504: and returning a setting result.
S1505: a second code block is invoked.
S1506: and setting a calling interface corresponding to the second exception handling code block at an interface of calling the running environment at the place where the exception monitoring is required to be set, and starting an exception handling mechanism.
S1507: pushing a second interface address corresponding to the second exception handling code block into an exception handling stack to serve as an exception handling method of the second code block.
S1508: and returning a setting result.
S1509: and (3) when an abnormality occurs in the execution process of the second code block, setting the running environment to be in an abnormal state.
S1510: and popping up the interface address corresponding to the second exception handling code block from the stack top of the exception handling stack. And determining a calling interface of the second exception handling code block according to the second interface address, and calling the second exception handling code block.
S1511: and calling a second exception handling code block to handle the exception.
S1512: and executing the second exception handling code block.
S1513: the exception is severe and executing the second exception handling code block cannot completely resolve the exception.
S1514: and popping up a first interface address corresponding to the first exception handling code block from the stack top of the exception handling stack. A call interface of the first exception handling code block may be determined based on the first interface address, the first exception handling code block being called.
S1515: the first exception handling code block is invoked to handle an exception.
S1516: a first exception handling code block is executed.
S1517: and (4) successfully processing the exception, clearing the exception state of the running environment, and returning an exception processing result, wherein the exception processing result is 0.
S1518: and continuing to execute the code block according to the exception handling result, namely, if the exception result is 0, resuming to execute the second code block.
S1519: and after the second code block is executed, continuing to execute the next code statement in the first code block, which calls the code statement of the second code block.
S1520: and continuing to execute the code according to the code statement of the first code block.
The embodiments of the present application provide some specific implementations of a method for processing code exceptions, and based on this, the present application further provides a corresponding apparatus. The apparatus provided in the embodiments of the present application will be described from the viewpoint of functional modularization.
Referring to fig. 16, fig. 16 is a schematic structural diagram of a code exception handling apparatus 1600 according to an embodiment of the present application, where the apparatus 1600 includes an execution module 1601, a determination module 1602, a push-in module 1603, a pop-up module 1604, and a processing module 1605.
An execution module 1601, configured to execute a first code block, where the first code block is a set of code statements;
a determining module 1602, configured to determine, according to a first exception monitor code statement in the first code block, a first interface address corresponding to a first exception handling code block for handling an exception in the execution process of the first application code;
a pushing module 1603, configured to push the first interface address into an exception handling stack, where the exception handling stack is configured to store an interface address corresponding to an exception handling code block;
a pop module 1604 configured to pop the first interface address from the exception handling stack when an exception occurs during execution of the first code block;
and the processing module 1605 is configured to call the first exception handling code block according to the first interface address to perform exception handling.
The embodiment of the application provides a code exception handling device. Executing a first code block, determining a first interface address according to a first exception monitoring code statement in the first code block, and pushing the first interface address into an exception handling stack; then, when an abnormality occurs in the execution process of the first code block, the first interface address is popped up from the abnormality processing stack; and finally, calling a first exception handling code block to handle the exception according to the first interface address so as to complete exception handling. Thus, by storing the exception handling code block separately from the code block, the encoding of the exception handling code into the program code is avoided, and the amount of code in the program code can be reduced. When an abnormality occurs in the execution process of the program code, the abnormality processing code block can be directly called from an interface address in an abnormality processing stack, so that the abnormality occurring in the execution process of the program code is processed; if no exception occurs in the execution process of the program code, the exception processing code block is not required to be called, and only the code statement in the code block is executed. And the exception handling codes scattered in the program codes are uniformly written and stored, so that the effect of simplifying the program codes is achieved. In this way, the amount of code in the program code can be reduced.
In one embodiment provided herein, the first code block includes a call to a second code block code statement, and the apparatus 1600 further includes:
and the calling module is used for calling the second code block according to the code statement of the second code block.
In one embodiment provided in the present application, the second code block includes a second exception monitor code statement, and the calling module is specifically configured to:
determining a second interface address corresponding to a second exception handling code block for handling exceptions in the execution process of the second code block according to the second exception monitoring code statement;
pushing the second interface address to the exception handling stack.
In one embodiment provided in the present application, the second code block does not include a second exception monitor code statement, and the calling module is specifically configured to:
when an exception occurs in the execution process of the second code block, popping the first interface address from the exception handling stack;
and calling the first exception handling code block according to the first interface address to perform exception handling.
In one embodiment provided in the present application, the calling module is specifically configured to:
when an exception occurs in the execution process of the second code block, popping the second interface address from the exception handling stack;
and calling the second code block to perform exception handling according to the second interface address.
In one embodiment provided in the present application, the first exception monitor code statement is not included in the first code block, and the apparatus 1600 further includes;
and the protection module is used for calling a preset exception handling code block to perform exception handling when an exception occurs in the execution process of the first code block.
In one embodiment provided herein, the apparatus 1600 further includes:
and the recovery module is used for continuing to execute the code blocks according to the exception handling result after the exception handling is completed.
The embodiment of the application also provides corresponding equipment and a computer storage medium, which are used for realizing the scheme provided by the embodiment of the application.
The device comprises a memory and a processor, wherein the memory is used for storing instructions or codes, and the processor is used for executing the instructions or codes so that the device can execute the code exception processing method according to any embodiment of the application.
The computer storage medium stores codes, and when the codes are executed, equipment for executing the codes realizes the code exception handling method in any embodiment of the application.
The "first" and "second" in the names of "first", "second" (where present) and the like in the embodiments of the present application are used for name identification only, and do not represent the first and second in sequence.
From the above description of embodiments, it will be apparent to those skilled in the art that all or part of the steps of the above described example methods may be implemented in software plus general hardware platforms. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which may be stored in a storage medium, such as a read-only memory (ROM)/RAM, a magnetic disk, an optical disk, or the like, including several instructions for causing a computer device (which may be a personal computer, a server, or a network communication device such as a router) to perform the methods described in the embodiments or some parts of the embodiments of the present application.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments for relevant points. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
The foregoing is merely exemplary embodiments of the present application and is not intended to limit the scope of the present application.

Claims (10)

1. A method for processing code exceptions, the method comprising:
executing a first code block, wherein the first code block is a group of code sentences;
determining a first interface address corresponding to a first exception handling code block for handling exceptions in the execution process of the first application program code according to a first exception monitoring code statement in the first code block;
pushing the first interface address into an exception handling stack, wherein the exception handling stack is used for storing the interface address corresponding to the exception handling code block;
when an exception occurs in the execution process of the first code block, popping the first interface address from the exception handling stack;
and calling the first exception handling code block according to the first interface address to perform exception handling.
2. The method of claim 1, wherein the first code block includes invoking a second code block code statement, the method further comprising:
and calling the second code block according to the code statement of the second code block.
3. The method of claim 2, wherein the second code block includes a second exception monitor code statement, and wherein the invoking the second code block includes:
determining a second interface address corresponding to a second exception handling code block for handling exceptions in the execution process of the second code block according to the second exception monitoring code statement;
pushing the second interface address to the exception handling stack.
4. The method of claim 2, wherein the second code block does not include a second exception monitor code statement, the invoking the second code block comprising:
when an exception occurs in the execution process of the second code block, popping the first interface address from the exception handling stack;
and calling the first exception handling code block according to the first interface address to perform exception handling.
5. A method according to claim 3, wherein said invoking a second code block comprises:
when an exception occurs in the execution process of the second code block, popping the second interface address from the exception handling stack;
and calling the second code block to perform exception handling according to the second interface address.
6. The method of claim 1, wherein the first exception monitor code statement is not included in the first code block, the method further comprising:
and when an abnormality occurs in the execution process of the first code block, calling a preset abnormality processing code block to perform abnormality processing.
7. The method according to any one of claims 1-6, further comprising:
and after the exception handling is completed, continuing to execute the code blocks according to the exception handling result.
8. A code exception handling apparatus, the apparatus comprising:
the execution module is used for executing a first code block, wherein the first code block is a group of code sentences;
the determining module is used for determining a first interface address corresponding to a first exception handling code block for handling exceptions in the execution process of the first application program code according to a first exception monitoring code statement in the first code block;
the pushing module is used for pushing the first interface address into an exception handling stack, and the exception handling stack is used for storing the interface address corresponding to the exception handling code block;
the pop-up module is used for popping up the first interface address from the exception handling stack when an exception occurs in the execution process of the first code block;
and the processing module is used for calling the first exception handling code block according to the first interface address to perform exception handling.
9. A computer device, comprising: a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the code exception handling method of any one of claims 1 to 7 when the computer program is executed.
10. A computer storage medium having instructions stored therein which, when executed on a terminal device, cause the terminal device to perform the code exception handling method of any of claims 1 to 7.
CN202310392270.0A 2023-04-13 2023-04-13 Code exception handling method, device, equipment and storage medium Active CN116126735B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310392270.0A CN116126735B (en) 2023-04-13 2023-04-13 Code exception handling method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310392270.0A CN116126735B (en) 2023-04-13 2023-04-13 Code exception handling method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN116126735A true CN116126735A (en) 2023-05-16
CN116126735B CN116126735B (en) 2023-08-15

Family

ID=86301284

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310392270.0A Active CN116126735B (en) 2023-04-13 2023-04-13 Code exception handling method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116126735B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5692146A (en) * 1995-05-26 1997-11-25 National Semiconductor Corporation Method of implementing fast 486TM microprocessor compatible string operations
CN109542657A (en) * 2018-10-16 2019-03-29 深圳壹账通智能科技有限公司 The processing method and server of system exception
CN113867847A (en) * 2021-11-30 2021-12-31 统信软件技术有限公司 Abnormal plug-in processing method and device and computing equipment
CN114296988A (en) * 2022-01-04 2022-04-08 成都知道创宇信息技术有限公司 Exception handling method and device, electronic equipment and storage medium
CN114528201A (en) * 2021-11-16 2022-05-24 平安银行股份有限公司 Abnormal code positioning method, device, equipment and medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5692146A (en) * 1995-05-26 1997-11-25 National Semiconductor Corporation Method of implementing fast 486TM microprocessor compatible string operations
CN109542657A (en) * 2018-10-16 2019-03-29 深圳壹账通智能科技有限公司 The processing method and server of system exception
CN114528201A (en) * 2021-11-16 2022-05-24 平安银行股份有限公司 Abnormal code positioning method, device, equipment and medium
CN113867847A (en) * 2021-11-30 2021-12-31 统信软件技术有限公司 Abnormal plug-in processing method and device and computing equipment
CN114296988A (en) * 2022-01-04 2022-04-08 成都知道创宇信息技术有限公司 Exception handling method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN116126735B (en) 2023-08-15

Similar Documents

Publication Publication Date Title
US7500245B2 (en) Changing code execution path using kernel mode redirection
CN108228077B (en) Storage area management method, operation method, device, equipment and readable medium
CN111240892A (en) Data backup method and device
CN108509322B (en) Method for avoiding excessive return visit, electronic device and computer readable storage medium
CN105573788B (en) The method and apparatus of patch processing and the method and apparatus for generating patch
CN106997313B (en) Signal processing method and system of application program and terminal equipment
CN116126735B (en) Code exception handling method, device, equipment and storage medium
WO2024113534A1 (en) Method and apparatus for controlling storage resources in storage node, and storage node
EP2835935A1 (en) Method for processing online upgrade, device and system thereof
CN116450165A (en) Method, system, terminal and storage medium for quickly building environment and deploying program
US6606640B2 (en) Method, computer program product, and system for modifying populated databases utilizing a reload utility
CN114443580A (en) Data cleaning method, device, medium and computing equipment
US6856994B2 (en) System and method for condensing application software
JPH0786841B2 (en) Fault information logging method and data processing device
CN112286625B (en) Mirror cache state management method and system based on multiple users of cloud platform
CN111124737A (en) Cloud platform operation conflict judgment method and electronic equipment
CN113347479B (en) Editing method, device, equipment and storage medium of multimedia material
CN114443101B (en) System advanced audit policy updating method, system, terminal and storage medium
CN110647526B (en) Batch data processing method, device, computer equipment and storage medium
CN117076004B (en) Micro-service packaging and merging method and device and electronic equipment
CN1151436C (en) Method of loading operation system and application program into memory
JP2000148562A (en) Data backup method, data backup device utilizing the method and computer readable recording medium recorded with data backup program
CN116048787A (en) Asynchronous calling method and device
US20020010914A1 (en) Componentware creating method and recording medium
JP2000155677A (en) Method for preventing runaway of program and computer system for the method and recording medium for recording program for preventing runaway

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
GR01 Patent grant
GR01 Patent grant