A code exception processing method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202211379631.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-04
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2042-11-04
AI Technical Summary
Existing technologies involve a large workload and high maintenance difficulty in handling code exceptions, which affects code readability and maintenance difficulty. Furthermore, exception information is not easily standardized, resulting in low code reuse rate and increased project development costs.
By using AOP principles to insert aspect code files, the listener function is determined through the effective path class and pointcut, and exceptions are captured and categorized for unified exception handling.
It reduced the amount of code development, improved development efficiency, simplified business code, enhanced code readability and maintainability, and unified exception handling logic and return encoding.
Smart Images

Figure CN115687128B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and specifically to a code exception handling method, apparatus, electronic device, and storage medium. Background Technology
[0002] In software code development, handling exception logic is one of the most frequently encountered problems. For developers, the simplest and most direct approach is to use try-catch blocks to catch system exceptions. However, this method requires developers to write a large amount of code, and exception information is not easy to maintain uniformly, increasing the development workload and potentially leading to uncaught exceptions. Furthermore, the presence of a large amount of repetitive exception handling code can interfere with testers' statistics on business code coverage during functional testing, affecting the accuracy of data statistics. Simultaneously, the presence of a large amount of exception handling code in business code affects readability and increases the difficulty of maintaining business code. Moreover, the lack of uniformity in exception handling logic results in low code reusability, requiring significant code modifications when changing or upgrading exception handling logic, increasing the difficulty of code upgrades and modifications, and increasing project development costs.
[0003] Therefore, there is an urgent need for a simple and convenient method for handling code exceptions. Summary of the Invention
[0004] The purpose of this invention is to overcome the above-mentioned technical deficiencies and provide a code exception handling method, device, electronic device and storage medium that can be used in financial technology or other related technical fields, and to solve the technical problems of large workload and high maintenance difficulty in code exception handling in the prior art.
[0005] To achieve the above-mentioned technical objectives, the present invention adopts the following technical solution:
[0006] In a first aspect, the present invention provides a code exception handling method, comprising the following steps:
[0007] Obtain the project source code, which contains aspect code files. These aspect code files define the effective path class, pointcut, and enhancement method of the aspect code files.
[0008] Based on the effective path class and pointcut in the aspect code file, determine the functions in the project source code that need to be monitored;
[0009] Based on the enhancement method of the aspect code file, capture the exceptions of the function that needs to be monitored;
[0010] The exceptions are categorized and processed according to the enhancement method of the aspect code file, so as to achieve unified processing of exceptions of the same type.
[0011] In some embodiments, the enhancement method is a surround enhancement method.
[0012] In some embodiments, the pointcut is all functions under the effective path class.
[0013] In some embodiments, the functions in the project source code that need to be monitored are determined based on the effective path class and pointcut of the aspect code file, including:
[0014] Based on the effective path class of the aspect code file, determine the target class in the project source code that needs to be monitored;
[0015] Based on the target class and the pointcut, determine the functions that need to be monitored under the target class.
[0016] In some embodiments, capturing exceptions of the function to be monitored based on the enhancement method of the aspect code file includes:
[0017] Based on the enhancement method of the aspect code file, obtain the function information of the function to be monitored, wherein the function information includes at least one of the class name, method name, and request parameter list;
[0018] The function information is processed using a preset exception test statement to obtain exceptions in the function information.
[0019] In some embodiments, classifying the exceptions according to the enhancement method of the aspect code file includes:
[0020] Based on the enhancement method of the aspect code file, the exception information of the exception is determined, and the exception information is used as the return object of the aspect code file, wherein the exception information is used to indicate the type of the exception.
[0021] In some embodiments, the exception information includes at least the exception type, exception code, and exception stack information.
[0022] Secondly, the present invention also provides a code exception handling apparatus, comprising:
[0023] The acquisition module is used to acquire the project source code, wherein aspect code files are inserted into the project source code, and the aspect code files define the effective path class, pointcuts and enhancement methods of the aspect code files;
[0024] The listener function determination module is used to determine the functions in the project source code that need to be listened to based on the effective path class and pointcut of the aspect code file;
[0025] An exception handling module is used to capture exceptions of the function to be monitored, based on the enhancement method of the aspect code file.
[0026] The processing module is used to classify and process the exceptions according to the enhancement method of the aspect code file, so as to achieve unified processing of exceptions of the same type.
[0027] Thirdly, the present invention also provides an electronic device, comprising: a processor and a memory;
[0028] The memory stores computer programs that can be executed by the processor;
[0029] When the processor executes the computer program, it implements the steps in the code exception handling method described above.
[0030] Fourthly, the present invention also provides a computer-readable storage medium storing one or more programs that can be executed by one or more processors to implement the steps in the code exception handling method described above.
[0031] Compared with existing technologies, the code exception handling method, apparatus, electronic device, and storage medium provided by this invention first acquire project code, wherein aspect code files are inserted into the project source code. These aspect code files define the effective path class, pointcuts, and enhancement methods of the aspect code files. Then, based on the effective path class and pointcuts of the aspect code files, the functions in the project source code that need to be monitored are determined. Next, according to the enhancement methods of the aspect code files, exceptions of the functions that need to be monitored are captured. Finally, according to the enhancement methods of the aspect code files, the exceptions are classified and processed to achieve unified processing of exceptions of the same type. This invention's unified exception handling based on AOP principles can effectively capture code exceptions. Developers only need to focus on the implementation of business logic, without needing to repeatedly develop exception handling logic, reducing code development workload and improving development efficiency. Moreover, there is no duplicate exception handling logic code in the business code, making the business code more concise, increasing code readability and maintainability. Furthermore, unified exception handling according to exception type, and unified exception logic and return encoding, allow front-end developers and third-party interface personnel to uniformly handle exception information returned by interfaces. Attached Figure Description
[0032] Figure 1 This is a flowchart of the code exception handling method provided in the embodiments of the present invention;
[0033] Figure 2 This is a flowchart of step S200 in the code exception handling method provided in this embodiment of the invention;
[0034] Figure 3 This is a flowchart of step S300 in the code exception handling method provided in this embodiment of the invention;
[0035] Figure 4 This is a schematic diagram of the functional modules of the code exception handling device provided in an embodiment of the present invention;
[0036] Figure 5 This is a schematic diagram of the hardware structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation
[0037] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0038] Please see Figure 1 , Figure 1 This is a flowchart illustrating a code exception handling method provided in an embodiment of the present invention. The code exception handling method involved in this embodiment can be executed by an electronic device capable of receiving or sending data, and can be various electronic devices with a display screen and supporting web browsing, including but not limited to smartphones, tablets, portable computers, and desktop servers, etc. Figure 1 As shown, the method specifically includes the following steps S100 to S400.
[0039] S100. Obtain the project source code, wherein the project source code contains an aspect code file, and the aspect code file defines the effective path class, pointcut, and enhancement method of the aspect code file.
[0040] In this embodiment, the project source code is first obtained from the project code management repository GitLab using the `git clone` command. Then, a Java aspect code file is added to the project source code. This aspect code file is a file programmed using AOP (Aspect-Oriented Programming) technology. AOP is a technique that uses pre-compilation and runtime dynamic proxies to achieve unified maintenance of program functionality. AOP can isolate different parts of business logic, thereby reducing coupling between them, improving program reusability, and increasing development efficiency. The aspect code file can perform specific actions by defining its aspects, join points, pointcuts, and enhancement methods. Therefore, after adding the Java aspect code file to the project source code, the file is marked as an aspect code class by using the `@Aspect` annotation at the class declaration location. The aspect code then applies to classes at the specified path by setting the exception handling path in the `@pointcut` annotation within the file. For example, to perform unified exception handling for exceptions in the controller and services classes of a project, the specified classpath address would be: @pointcut(""execution(*.*controller.*(..),*.*services.*(..))"").
[0041] Furthermore, by configuring the enhancement (advice) settings of the aspect code file, the specific operations to be performed by the program points defined in the pointcut are defined. The before, after, and around methods are used to distinguish whether the code is executed before, after, or as a replacement for each joint point.
[0042] S200. Based on the effective path class and pointcut of the aspect code file, determine the functions in the project source code that need to be monitored.
[0043] In this embodiment, after the aspect code file is defined, it is inserted into the project source code. Then, the functions that need to be monitored in the project source code can be determined through the effective path class and pointcut of the aspect code file. Thus, anomaly detection can be performed on the functions that need to be monitored. All functions that need to be monitored can be quickly obtained without redeveloping code, which is simple, convenient and increases development efficiency.
[0044] S300. Based on the enhancement method of the aspect code file, capture the exception of the function that needs to be monitored.
[0045] In this embodiment, since the enhancement method defines the specific operations to be performed by all the functions that need to be monitored within the pointcut, function exceptions are captured using this enhancement method after the functions to be monitored are obtained. For example, before exception capture, the actual class name, actual method name, and request parameter list of each function can be obtained; after exception capture, the exception type can be obtained, thereby enabling rapid exception handling.
[0046] S400. Based on the enhancement method of the aspect code file, the exceptions are classified and processed to achieve unified processing of exceptions of the same type.
[0047] In this embodiment, after the exception is captured, the captured exception is classified and processed. After the exception is obtained, the exception type is obtained through getClass.getName. There are multiple exception types. By performing unified exception handling, the exception code and exception logic processing are unified. This allows front-end developers and third-party interface personnel to uniformly handle the exception codes returned by the interface.
[0048] This invention first obtains the project code, which contains aspect code files. These aspect code files define the effective path class, pointcuts, and enhancement methods. Then, based on the effective path class and pointcuts, the functions in the project source code that need to be monitored are determined. Next, according to the enhancement methods in the aspect code files, exceptions in the functions that need to be monitored are captured. Finally, based on the enhancement methods in the aspect code files, the exceptions are categorized and processed to achieve unified handling of exceptions of the same type. This invention, based on AOP principles, implements unified exception handling, which can effectively capture code exceptions. Developers only need to focus on the implementation of business logic, without having to repeatedly develop exception handling logic, reducing code development workload and improving development efficiency. Moreover, there is no duplicate exception handling logic code in the business code, making the business code more concise, increasing code readability and maintainability. Furthermore, unified exception handling based on exception type, and unified exception logic and return encoding, allow front-end developers and third-party interface personnel to uniformly handle exception information returned by interfaces.
[0049] In some embodiments, the enhancement method is an around enhancement method, i.e., aop for Around enhancement processing. The @Around annotation is used to modify Around enhancement processing. Around enhancement processing is a more powerful enhancement processing method, similar to a summary of Before and AfterReturning enhancement processing. Around enhancement processing can enhance actions before or after the execution of the target method. Unlike Before and AfterReturning enhancement processing, Around enhancement processing can determine when and how the target method is executed, and can even completely prevent the execution of the target method. When an Around enhancement processing method is defined, the first parameter of the method must be of type ProceedJoinPoint (containing at least one parameter). Within the enhancement processing method body, the target method will only be executed when the proceeded() method of the ProceedingJoinPoint parameter is called—this is the key to Around enhancement processing's complete control over when and how the method is executed; if the program does not call the proceed() method of the ProceedingJoinPoint parameter, the target method will not be executed.
[0050] For example, you can use the @Around(“pintcut()”) annotation to surround all functions of a class under a specified path and listen for relevant information during the function execution process.
[0051] In some embodiments, the cutoff point is all functions under the effective path class. That is, the embodiments of the present invention monitor all functions under the effective path class, thereby enabling the detection of all exceptions under the effective path class. This avoids adding repetitive exception handling logic code while ensuring the comprehensiveness of exception detection, reducing code development workload, and improving development efficiency.
[0052] In some embodiments, please refer to Figure 2 Step S200 specifically includes:
[0053] S210. Based on the effective path class of the aspect code file, determine the target class that needs to be monitored in the project source code;
[0054] S220. Based on the target class and the pointcut, determine the functions that need to be monitored under the target class.
[0055] In this embodiment, the effective path class can be declared through the aspect in the aspect code file. The aspect declaration is similar to the class declaration in Java. The aspect contains some pointcuts and corresponding advice. Therefore, the target class to be listened to can be determined through the aspect declaration.
[0056] After determining the target class, the function to be monitored can be further determined through pointcuts. An aspect represents a set of joint points, which are either combined through logical relationships or grouped together through wildcards, regular expressions, etc. It defines where the corresponding advice will occur. Therefore, the specific function to be monitored under the target class can be determined through pointcuts.
[0057] In some embodiments, please refer to Figure 3 Step S300 specifically includes:
[0058] S310. Based on the enhancement method of the aspect code file, obtain the function information of the function to be monitored, wherein the function information includes at least one of the class name, method name, and request parameter list;
[0059] S320. The function information is processed using a preset exception test statement to obtain the exceptions in the function information.
[0060] In this embodiment, all functions of a class under a specified path are surrounded by the `@Around("patch()")` annotation to monitor relevant information during function execution. For example, the actual class name is obtained via `ProceedingJoinPoint.getTarget().getClass.getName`, the actual method name via `ProceedingJoinPoint.getSignature.getName`, and the request parameter list via `ProceedingJoinPoint.getArgs`. Then, exceptions occurring in the `ProceedingJoinPoint.processed()` method are caught using a try-catch statement. The caught exceptions are those generated during the execution of the business logic code. The try-catch statement includes a try block and a catch block. Code that might throw exceptions is included in the try block, and code that handles exceptions is included in the catch block. During program execution, if an error occurs in the try block, the try block creates an exception object and throws it. The catch block catches the exception object, and the code within the catch block executes, thus capturing the exception from the function information.
[0061] In some embodiments, classifying the exceptions according to the enhancement method of the aspect code file includes:
[0062] Based on the enhancement method of the aspect code file, the exception information of the exception is determined, and the exception information is used as the return object of the aspect code file, wherein the exception information is used to indicate the type of the exception.
[0063] Preferably, the exception information includes at least the exception type, exception code, and exception stack information.
[0064] In this embodiment, after an exception is detected, the exception type is obtained using `getClass.getName` in the enhanced method. For example, if the exception type is `ArithmeticException`, it is an arithmetic exception class, the exception code is set to 501, and the exception stack trace is printed using `printStackTrace()`. If the exception type is `IllegalArgumentException`, it is an illegal parameter exception, the exception code is set to 502, and the exception stack trace is printed using `printStackTrace()`. If the exception type is `NullPointerException`, it is a null pointer exception, the exception code is set to 503, and the exception stack trace is printed using `printStackTrace()`. If the exception type is `ArrayIndexOutOfBoundsException`, it is an array index out of bounds exception, the exception code is set to 504, and the exception stack trace is printed using `printStackTrace()`. If the exception type is not one of the above exception types, it is an unknown exception, the exception code is set to 500, and the exception stack trace is printed using `printStackTrace()`.
[0065] The exception type, exception code, and exception stack trace are written into the defined exception object, which is then returned as the object of the aspect function.
[0066] The technical solution provided by this invention first obtains the project code, wherein aspect code files are inserted into the project source code. These aspect code files define the effective path class, pointcuts, and enhancement methods. Then, based on the effective path class and pointcuts of the aspect code files, the functions in the project source code that need to be monitored are determined. Next, according to the enhancement methods of the aspect code files, exceptions of the functions that need to be monitored are captured. Finally, based on the enhancement methods of the aspect code files, the exceptions are classified and processed to achieve unified processing of exceptions of the same type. This invention's unified exception handling based on AOP principles can effectively capture code exceptions. Developers only need to focus on the implementation of business logic, without needing to repeatedly develop exception handling logic, reducing code development workload and improving development efficiency. Furthermore, the absence of duplicate exception handling logic in the business code makes the business code more concise, increasing readability and maintainability. In addition, unified exception handling based on exception type, and unified exception logic and return encoding, allows front-end developers and third-party interface personnel to uniformly handle exception information returned by interfaces.
[0067] Another embodiment of the present invention provides a code exception handling device; please refer to [link to relevant documentation]. Figure 4 The code exception handling device includes an acquisition module 11, a listening function determination module 12, an exception capture module 13, and a processing module 14.
[0068] The acquisition module 11 is used to acquire the project source code, wherein the project source code contains an aspect code file, and the aspect code file defines the effective path class, pointcut, and enhancement method of the aspect code file.
[0069] The listening function determination module 12 is used to determine the functions that need to be listened to in the project source code based on the effective path class and pointcut of the aspect code file.
[0070] The exception capture module 13 is used to capture exceptions of the function that needs to be monitored, based on the enhancement method of the aspect code file.
[0071] The processing module 14 is used to classify and process the exceptions according to the enhancement method of the aspect code file, so as to achieve unified processing of exceptions of the same type.
[0072] In this embodiment, the project code is first obtained, wherein aspect code files are inserted into the project source code. These aspect code files define the effective path class, pointcuts, and enhancement methods. Then, based on the effective path class and pointcuts of the aspect code files, the functions in the project source code that need to be monitored are determined. Next, according to the enhancement methods of the aspect code files, exceptions of the functions that need to be monitored are captured. Finally, based on the enhancement methods of the aspect code files, the exceptions are classified and processed to achieve unified processing of exceptions of the same type. This invention, based on AOP principles, implements unified exception handling, which can effectively capture code exceptions. Developers only need to focus on the implementation of business logic, without having to repeatedly develop exception handling logic, reducing code development workload and improving development efficiency. Moreover, there is no duplicate exception handling logic code in the business code, making the business code more concise, increasing code readability and maintainability. Furthermore, unified exception handling based on exception type, and unified exception logic and return encoding, allow front-end developers and third-party interface personnel to uniformly handle exception information returned by interfaces.
[0073] It should be noted that the module referred to in this invention refers to a series of computer program instruction segments that can perform specific functions. It is more suitable than a program for describing the execution process of code exception handling. For the specific implementation of each module, please refer to the corresponding method embodiments above, which will not be repeated here.
[0074] In some embodiments, the enhancement method is a surround enhancement method.
[0075] In some embodiments, the pointcut is all functions under the effective path class.
[0076] In some embodiments, the listening function determination module 12 is specifically used for:
[0077] Based on the effective path class of the aspect code file, determine the target class in the project source code that needs to be monitored;
[0078] Based on the target class and the pointcut, determine the functions that need to be monitored under the target class.
[0079] In some embodiments, the exception capture module 13 is specifically used for:
[0080] Based on the enhancement method of the aspect code file, obtain the function information of the function to be monitored, wherein the function information includes at least one of the class name, method name, and request parameter list;
[0081] The function information is processed using a preset exception test statement to obtain exceptions in the function information.
[0082] In some embodiments, the processing module 14 is specifically used for:
[0083] Based on the enhancement method of the aspect code file, the exception information of the exception is determined, and the exception information is used as the return object of the aspect code file, wherein the exception information is used to indicate the type of the exception.
[0084] In some embodiments, the exception information includes at least the exception type, exception code, and exception stack information.
[0085] Another embodiment of the present invention provides an electronic device, such as... Figure 5 As shown, the electronic device 10 includes:
[0086] One or more processors 110 and memory 120, Figure 5 The following description uses a processor 110 as an example. The processor 110 and the memory 120 can be connected via a bus or other means. Figure 5 Taking the example of a connection between China and Israel via a bus.
[0087] Processor 110 is used to perform various control logics of electronic device 10. It can be a general-purpose processor, digital signal processor (DSP), application-specific integrated circuit (ASIC), field-programmable gate array (FPGA), microcontroller, ARM (Acorn RISC Machine) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination of these components. Furthermore, processor 110 can also be any conventional processor, microprocessor, or state machine. Processor 110 can also be implemented as a combination of computing devices, such as a combination of DSP and microprocessor, multiple microprocessors, one or more microprocessors combined with DSP and / or any other such configuration.
[0088] The memory 120, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as the program instructions corresponding to the code exception handling method in the embodiments of the present invention. The processor 110 executes various functional applications and data processing of the electronic device 10 by running the non-volatile software programs, instructions, and units stored in the memory 120, thereby implementing the code exception handling method in the above method embodiments.
[0089] The memory 120 may include a program storage area and a data storage area. The program storage area may store applications required for the operating platform and at least one function; the data storage area may store data created based on the use of the electronic device 10. Furthermore, the memory 120 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 120 may optionally include memory remotely located relative to the processor 110, and these remote memories may be connected to the electronic device 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0090] One or more units are stored in memory 120. When executed by one or more processors 110, they execute the code exception handling method in any of the above method embodiments, for example, executing the methods described above. Figure 1 Method steps S100 to S400.
[0091] Another embodiment of the present invention provides a computer-readable storage medium storing computer-executable instructions that are executed by one or more processors, for example, to perform the above-described instructions. Figure 1 Method steps S100 to S400.
[0092] As an example, computer-readable storage media can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) as external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms such as synchronous RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), and direct Rambus RAM (DRRAM). The memory components or memories disclosed in the operating environment described herein are intended to include one or more of these and / or any other suitable types of memory.
[0093] In summary, the code exception handling method, apparatus, electronic device, and storage medium provided by this invention first acquire project code, wherein aspect code files are inserted into the project source code. These aspect code files define the effective path class, pointcuts, and enhancement methods of the aspect code files. Then, based on the effective path class and pointcuts of the aspect code files, the functions in the project source code that need to be monitored are determined. Next, according to the enhancement methods of the aspect code files, exceptions of the functions that need to be monitored are captured. Finally, according to the enhancement methods of the aspect code files, the exceptions are classified and processed to achieve unified processing of exceptions of the same type. This invention's unified exception handling based on AOP principles can effectively capture code exceptions. Developers only need to focus on the implementation of business logic, without needing to repeatedly develop exception handling logic, reducing code development workload and improving development efficiency. Moreover, there is no duplicate exception handling logic code in the business code, making the business code more concise, increasing code readability and maintainability. Furthermore, unified exception handling according to exception type, and unified exception logic and return encoding, allow front-end developers and third-party interface personnel to uniformly handle exception information returned by interfaces.
[0094] The specific embodiments of the present invention described above do not constitute a limitation on the scope of protection of the present invention. Any other corresponding changes and modifications made in accordance with the technical concept of the present invention should be included within the scope of protection of the claims of the present invention.
Claims
1. A code exception handling method, characterized in that, Includes the following steps: Obtain the project source code, which contains aspect code files. These aspect code files define the effective path class, pointcut, and enhancement method of the aspect code files. Based on the effective path class and pointcut in the aspect code file, determine the functions in the project source code that need to be monitored; Based on the enhancement method of the aspect code file, capture the exceptions of the function that needs to be monitored; Based on the enhancement method of the aspect code file, the exceptions are classified and processed to achieve unified processing of exceptions of the same type; Based on the effective path class and pointcut in the aspect code file, determine the functions in the project source code that need to be monitored, including: Based on the effective path class of the aspect code file, determine the target class in the project source code that needs to be monitored; Based on the target class and the pointcut, determine the functions that need to be monitored under the target class; The method of capturing exceptions in the function to be monitored, based on the enhancement method of the aspect code file, includes: Based on the enhancement method of the aspect code file, obtain the function information of the function to be monitored, wherein the function information includes at least one of the class name, method name, and request parameter list; The function information is processed using a preset exception test statement to obtain exceptions in the function information; The step of classifying and processing the exceptions according to the enhancement method of the aspect code file includes: Based on the enhancement method of the aspect code file, the exception information of the exception is determined, and the exception information is used as the return object of the aspect code file, wherein the exception information is used to indicate the type of the exception; The exception information includes at least the exception type, exception code, and exception stack information.
2. The code exception handling method according to claim 1, characterized in that, The enhancement method is a surround enhancement method.
3. The code exception handling method according to claim 2, characterized in that, The cutoff point is all functions under the effective path class.
4. A code exception handling device, characterized in that, include: The acquisition module is used to acquire the project source code, wherein aspect code files are inserted into the project source code, and the aspect code files define the effective path class, pointcuts and enhancement methods of the aspect code files; The listener function determination module is used to determine the functions in the project source code that need to be listened to based on the effective path class and pointcut of the aspect code file; An exception handling module is used to capture exceptions of the function to be monitored, based on the enhancement method of the aspect code file. The processing module is used to classify and process the exceptions according to the enhancement method of the aspect code file, so as to achieve unified processing of exceptions of the same type; The monitoring function determination module is specifically used for: Based on the effective path class of the aspect code file, determine the target class in the project source code that needs to be monitored; Based on the target class and the pointcut, determine the functions that need to be monitored under the target class; The exception capture module is specifically used for: Based on the enhancement method of the aspect code file, obtain the function information of the function to be monitored, wherein the function information includes at least one of the class name, method name, and request parameter list; The function information is processed using a preset exception test statement to obtain exceptions in the function information; The processing module is specifically used for: Based on the enhancement method of the aspect code file, the exception information of the exception is determined, and the exception information is used as the return object of the aspect code file, wherein the exception information is used to indicate the type of the exception; The exception information includes at least the exception type, exception code, and exception stack information.
5. An electronic device, characterized in that, include: Processor and memory; The memory stores computer programs that can be executed by the processor; When the processor executes the computer program, it implements the steps of the code exception handling method as described in any one of claims 1-3.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores one or more programs, which can be executed by one or more processors to implement the steps in the code exception handling method as described in any one of claims 1-3.
Citation Information
Patent Citations
Information processing method and device, electronic equipment and storage medium
CN111459803A
Business process monitoring methods, devices, computer equipment, and storage media
CN114936136A
