Code exception processing method and device

By defining custom annotations and interceptors to handle exceptions, the complexity and messiness of exception handling in the code are solved, and the code is simplified and the efficiency of exception handling is improved.

CN121785576APending Publication Date: 2026-04-03BEIJING WODONG TIANJUN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

Existing technologies often employ overly complex and disorganized exception handling, resulting in poor code readability and maintainability, and low exception handling efficiency.

Method used

Define custom annotations to mark business classes with unified exception handling, configure interceptors as pointcuts using custom annotations, define exception handling logic in the interceptors, capture and process exception information in the code using interceptors, and achieve dynamic modification through aspect-oriented programming and dynamic proxy technology.

Benefits of technology

It simplifies the code structure, improves code readability and maintainability, and enhances the efficiency of exception handling.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121785576A_ABST
    Figure CN121785576A_ABST
Patent Text Reader

Abstract

The invention discloses a code exception processing method and device, and relates to the technical field of computers. A specific embodiment of the method comprises the following steps: defining a user-defined annotation; wherein the user-defined annotations are used for marking business classes of unified exception processing; configuring an interceptor by taking the user-defined annotation as a tangency point, and defining exception handling logic in the interceptor; and capturing code exception information corresponding to the business class of the unified exception processing by utilizing an interceptor, and processing the code exception information according to exception processing logic. According to the embodiment, the code structure can be simplified, so that the readability and maintainability of the code are improved, and the exception handling efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for handling code exceptions. Background Technology

[0002] Exception handling is an important technique in programming used to handle unexpected situations or errors that occur during program execution. The purpose of exception handling is to enable a program to handle errors and continue running normally if possible, or at least provide clear error information and safely terminate the program.

[0003] In the process of realizing this invention, the inventors discovered at least the following problems in the related technology:

[0004] Excessively complex or messy exception handling code leads to poor readability and maintainability, as well as low exception handling efficiency. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a method and apparatus for code exception handling, which simplifies the code structure, thereby improving the readability and maintainability of the code and increasing the efficiency of exception handling.

[0006] To achieve the above objectives, according to one aspect of the present invention, a method for code exception handling is provided, comprising:

[0007] Define custom annotations; these custom annotations are used to mark business classes that handle unified exceptions.

[0008] Configure interceptors using custom annotations as pointcuts, and define exception handling logic within the interceptors;

[0009] Interceptors are used to capture exception information in the code corresponding to the business class with unified exception handling, and the exception information is processed according to the exception handling logic.

[0010] Optionally, define custom annotations, including:

[0011] Create a custom annotation based on the obtained business keywords, and set the attributes of the custom annotation to the obtained unified exception handling business class.

[0012] Optionally, custom annotations can be configured as pointcut interceptors, including:

[0013] Configure pointcut expressions in aspect classes for aspect-oriented programming, and associate interceptors with custom annotations based on pointcut expressions.

[0014] Optionally, the method further includes:

[0015] Utilize dynamic proxy technology to configure aspect-oriented programming (AOP), enabling AOP to dynamically modify exception handling logic at runtime.

[0016] Optionally, after processing the exception information in the code according to the exception handling logic, the method further includes:

[0017] The response object corresponding to the processing result is generated based on the predefined general output parameter conversion logic; the response object includes the status code and message information.

[0018] Optionally, the method further includes:

[0019] Identify non-business exception information in the code exception information, and generate system exception messages corresponding to the system exceptions based on the non-business exception information.

[0020] According to a second aspect of the present invention, an apparatus for code exception handling is provided, comprising:

[0021] The definition module is used to define custom annotations; these custom annotations are used to mark business classes that handle unified exceptions.

[0022] The configuration module is used to configure interceptors by using custom annotations as pointcuts, and to define exception handling logic in the interceptors;

[0023] The processing module is used to capture code exception information corresponding to the business class with unified exception handling using interceptors, and process the code exception information according to the exception handling logic.

[0024] According to a third aspect of the present invention, an electronic device is provided, comprising:

[0025] One or more processors;

[0026] Memory, used to store one or more programs.

[0027] When one or more programs are executed by one or more processors, the one or more processors implement the methods of any of the above embodiments.

[0028] According to a fourth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method of any of the above embodiments.

[0029] According to a fifth aspect of the present invention, a computer program product is provided, including a computer program that, when executed by a processor, implements the method of any of the above embodiments.

[0030] One embodiment of the above invention has the following advantages or beneficial effects: by defining custom annotations; wherein the custom annotations are used to mark the business classes of unified exception handling; the custom annotations are configured as pointcuts to interceptors, and exception handling logic is defined in the interceptors; the interceptors are used to capture the code exception information corresponding to the business classes of unified exception handling, and the code exception information is processed according to the exception handling logic; thereby simplifying the code structure, improving the readability and maintainability of the code, and improving the efficiency of exception handling.

[0031] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description

[0032] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:

[0033] Figure 1 This is a schematic diagram of the main flow of the code exception handling method according to an embodiment of the present invention;

[0034] Figure 2 This is a schematic diagram of the main flow of a code exception handling method according to a preferred embodiment of the present invention;

[0035] Figure 3 This is a schematic diagram of the main modules of a code exception handling apparatus according to an embodiment of the present invention;

[0036] Figure 4 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;

[0037] Figure 5 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation

[0038] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0039] It should be noted that the acquisition, storage, and application of personal information involved in the embodiments of the present invention comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0040] Exception handling is an important technique in programming used to handle unexpected situations or errors that occur during program execution. The purpose of exception handling is to enable a program to handle errors and continue running normally if possible, or at least provide clear error messages and safely terminate the program. Currently, exception handling code is often overly complex or messy, resulting in poor readability and maintainability, and low exception handling efficiency.

[0041] In view of this, according to one aspect of the present invention, a method for code exception handling is provided.

[0042] Figure 1 This is a schematic diagram illustrating the main flow of a code exception handling method according to an embodiment of the present invention. Figure 1 As shown, the code exception handling method according to an embodiment of the present invention includes the following steps S101 to S103.

[0043] Step S101: Define a custom annotation; wherein, the custom annotation is used to mark the business class of unified exception handling.

[0044] Custom annotations are a metadata mechanism in Java that allows developers to define the required annotation types to add extra information or behavior to the code. Annotations themselves do not directly perform any operations; instead, they use reflection, tools, or frameworks to read this information and execute specific logic as needed. When defining custom annotations, you can use the `@interface` keyword to create annotation types and specify attributes such as `@Target` to specify the scope of the annotation's application and `@Retention` to specify the annotation's lifecycle. Business classes are classes in an application that handle specific business logic, processing actual business needs and operations, such as handling user requests and data processing. Business classes can call the data access layer or other auxiliary components to complete their tasks. Business classes with unified exception handling are classes specifically designed to handle exceptional situations. They centrally manage and handle various exceptional cases in the application, providing a consistent exception handling strategy. Defining unified exception handling logic for business classes, such as logging and error message generation, and ensuring proper handling when exceptions occur improves the stability and maintainability of the application.

[0045] When defining custom annotations to mark business classes with unified exception handling, you can first define an annotation type, such as "@ExceptionHandler". Use this annotation in the business class to mark those classes or methods that need exception handling. Through reflection or a framework (such as the Spring framework), these markers can be identified, and unified exception handling logic can be applied to the marked business classes. In this way, all business logic that needs exception handling can be managed and handled uniformly without having to repeatedly write exception handling code in each business class.

[0046] Step S102: Configure the interceptor as a pointcut using the custom annotation, and define the exception handling logic in the interceptor.

[0047] Interceptors are components in an application used to intercept and handle specific operations. They can operate before or after a request reaches the actual processing logic, addressing cross-cutting concerns such as exception handling, logging, or transaction management. In the Spring framework, interceptors can be implemented using AOP (Aspect-Oriented Programming) to intercept method calls and execute predefined operations. Exception handling logic refers to the code or strategies in an application that handle error conditions. It catches and processes exceptions to ensure the system continues to run when exceptions occur or to provide user-friendly error messages. Exception handling logic includes catching specific exception types, logging exception information, and returning error responses.

[0048] By configuring interceptors using custom annotations as pointcuts, Spring's AOP configuration allows you to define an aspect class that intercepts all method calls marked with the custom annotation. Within the aspect class, you can define specific exception handling logic, such as catching exceptions, logging, and processing exception information. The interceptor is triggered before or after the execution of the actual business method, executing the exception handling logic as needed. This approach enables unified exception handling across the application, eliminating the need to repeatedly write exception handling code in each business logic segment, thus improving code maintainability and consistency.

[0049] Step S103: Use an interceptor to capture the code exception information corresponding to the business class of unified exception handling, and process the code exception information according to the exception handling logic.

[0050] Code exception information refers to error messages that occur during program execution. These exceptions can be triggered by errors or exceptional conditions in the program code, including runtime errors, logical errors, invalid input, etc. Code exception information provides specific details about the exception, such as the type of exception, the location of the occurrence, and the associated error message. This information is helpful for debugging and fixing problems in the program. When using interceptors to capture code exception information corresponding to business classes with unified exception handling, the interceptors are triggered before or after the execution of the business method; that is, when a method throws an exception, the interceptor catches it. The process of catching exceptions involves using try-catch blocks in the interceptor's methods to catch and handle any exceptions that may be thrown. After catching the exception information, the exception handling logic in the interceptor processes it, including logging exceptions, generating user-friendly error messages, and implementing remedial measures. In this way, interceptors can provide a unified handling method when exceptions occur, ensuring that the system can gracefully handle errors while maintaining the stability and reliability of the application.

[0051] This invention simplifies the code structure, thereby improving code readability and maintainability, and increasing exception handling efficiency. It utilizes custom annotations to mark business classes with unified exception handling. The custom annotations are configured as pointcuts for interceptors, and exception handling logic is defined within the interceptors. The interceptors capture code exception information corresponding to the business classes with unified exception handling, and process the exception information according to the exception handling logic.

[0052] Optionally, define a custom annotation, including: creating a custom annotation based on the obtained business keywords, and setting the attributes of the custom annotation to the obtained unified exception handling business class.

[0053] When defining annotations, you can use Java's `@interface` keyword to create a new annotation type and add appropriate attributes to support exception handling. First, determine which attributes are needed to describe the exception handling logic; these can include exception handling strategies, error message templates, logging on / off switches, etc. Then, use the `@Target` annotation to specify the scope of the custom annotation (e.g., class, method) and the `@Retention` annotation to specify the retention strategy (e.g., `RUNTIME`, which reads annotation information at runtime via reflection). By applying custom annotations to business classes or methods, specific exception handling rules are specified for these classes or methods. In interceptors or aspect classes, unified exception handling logic can be implemented based on the annotation attributes, including reading annotation information at runtime and handling exceptions in business classes according to predefined exception handling strategies. Through custom annotations and a unified exception handling mechanism, exception handling logic in the system can be effectively managed and maintained, improving system stability and consistency.

[0054] Optionally, the custom annotation can be configured as a pointcut interceptor, including: configuring a pointcut expression in the aspect class of aspect-oriented programming, and associating the interceptor with the custom annotation based on the pointcut expression.

[0055] In Aspect-Oriented Programming (AOP), configuring pointcut expressions in aspect classes specifies which methods or classes an interceptor should apply to. A pointcut expression is a language for defining pointcuts, describing which join points (method calls or object instantiations) should be intercepted by the interceptor. In aspect classes, configuring pointcut expressions uses AOP language expression syntax to specify the selection criteria for methods. To associate an interceptor with a custom annotation, first use the custom annotation as a condition in the pointcut expression. For example, an expression can specify that the interceptor applies to all methods marked with a specific custom annotation. The pointcut expression defines the scope of the interceptor, enabling it to automatically identify business methods that require exception handling. In this way, the interceptor is associated with the custom annotation, ensuring that when a method is executed, if the method is marked with a custom annotation, the interceptor will intervene and apply the defined exception handling logic. In addition, methods are written in the definition of aspect classes to handle intercepted exceptions. These methods can be executed when the specified pointcut is triggered. By configuring pointcut expressions and defining aspect methods, aspect classes can intercept specified methods and perform corresponding exception handling based on the attributes of custom annotations, thereby providing a unified exception management and handling mechanism.

[0056] Optionally, the method further includes: configuring aspect-oriented programming using dynamic proxy technology so that aspect-oriented programming can dynamically modify exception handling logic at runtime.

[0057] Dynamic proxies are a technique that generates proxy objects at runtime, allowing the behavior of objects to be altered during program execution. In Aspect-Oriented Programming (AOP), dynamic proxies can be used to implement flexible aspect logic, enabling exception handling logic to be adjusted according to actual needs. In AOP, dynamic proxy technology allows the creation of a proxy object that can intercept and handle the execution of methods during invocation. In this way, custom exception handling logic can be inserted into the method call flow. The proxy object executes specific code before and after the actual method call, allowing for dynamic adjustment of this code at runtime, thereby changing the exception handling strategy or behavior. Specifically, an aspect class is defined, containing exception handling logic. A proxy object is generated using dynamic proxy technology. This proxy object delegates to the aspect class during method invocation. The aspect class can insert exception handling logic before and after the execution of the target method of the proxy object and dynamically modify the handling rules as needed. This approach provides great flexibility, allowing the exception handling logic to be changed at runtime without modifying the original business code or recompiling the program. Dynamic proxy technology, in implementing AOP, not only supports flexible exception handling but also provides unified exception management and monitoring, further improving the maintainability and reliability of the system.

[0058] Optionally, after processing the code exception information according to the exception handling logic, the method further includes: generating a response object corresponding to the processing result according to a predefined general output parameter conversion logic; wherein the response object includes a status code and message information.

[0059] The response object, generated based on predefined generic output parameter conversion logic, transforms the processing result into a standard response format for interaction with the client. The response object typically includes a status code and message information to convey the operation's result and related information. Specifically, a corresponding status code can be generated according to the type and status of the processing result, following generic conversion logic. Status codes indicate the processing status of the request, such as success, failure, or error. Generic status codes can include HTTP (Hypertext Transfer Protocol) status codes, such as 200 for success, 400 for client error, and 500 for server error. Choosing an appropriate status code helps the client quickly understand the processing result and current status of the request. Next, corresponding message information is generated based on the processing result. This message information includes a description of the operation result, detailed error information, or confirmation of success. Message information generation can be tailored to the specific circumstances of the processing result; for example, a confirmation message is returned upon success, while a detailed error description and suggested solutions are provided when an error occurs. Finally, the status code and message information are encapsulated into a response object to form the final response format, which facilitates client parsing and processing of the results, thereby achieving effective communication and user experience.

[0060] Optionally, the method further includes: determining non-business exception information in the code exception information, and generating a system exception message corresponding to the system exception based on the non-business exception information.

[0061] When handling code exception information, it's crucial to distinguish between business-related and non-business-related exceptions. Non-business-related exceptions refer to system-level problems such as runtime errors, resource unavailability, and database connection failures. These issues are not directly caused by specific business logic but rather by system environment or configuration problems. Once non-business-related exception information is identified, corresponding system exception messages can be generated based on it. The generation of system exception messages can be tailored to the type and severity of the exception, ensuring the message accurately reflects the nature and scope of the problem. System exception messages can include the root cause of the exception, the context in which it occurred, and possible solutions or remedial measures. This allows system administrators or developers to quickly locate and resolve problems. The process of generating system exception messages involves parsing the exception information and extracting key information, such as error codes, error descriptions, and stack traces. Based on this information, a clear error report or message is constructed, providing sufficient context to aid in troubleshooting and system maintenance, significantly improving the efficiency of responding to system problems and the effectiveness of problem-solving.

[0062] Figure 2 This is a schematic diagram of the main flow of a code exception handling method according to a preferred embodiment of the present invention. Figure 2 As shown, a unified strategy for handling code exceptions can improve code maintainability, reusability, and scalability. Extracting common functionalities into independent modules or components allows for shared use in multiple places, reducing the workload of repetitive code writing and making the code clearer, more concise, and less redundant. When adding new functionalities, modifications or extensions only need to be made to the unified functionality handling area, eliminating the need for modifications in multiple places and reducing code coupling.

[0063] Step S201: Define a custom annotation @BaseGateWay. In Java, custom annotations can be defined using the @interface keyword. In this embodiment, a custom annotation @BaseGateWay is defined and decorated with the @EasyGateWay annotation.

[0064] Step S202 involves registering the BaseGateWay interceptor, using a custom annotation as a pointcut and the interceptor as an enhancement process, weaving it into the configuration class. Specifically, when a class is annotated with the custom annotation @BaseGateWay, the called target method will enter the interceptor logic. When an exception occurs in the interface implementation, the interceptor's exception handling logic will be triggered. Specifically, an interceptor is registered, whose function includes executing specified logic before and after request processing. The interceptor can include preprocessing, postprocessing, and post-processing functions to ensure comprehensive interception and processing of the request. An aspect class is created to define the pointcut and specify where interception occurs. In the aspect class, annotations are used to identify the methods or classes to be intercepted, such as executing before or after the method. The interceptor is registered in the configuration class, and the aspect class is woven in as an aspect. By configuring the configuration class, we ensure that the interceptor is correctly registered and woven into the aspect class to achieve interception processing of custom annotations. Enabling AspectJ proxy in the configuration class ensures that the aspect class can be correctly woven into the application to achieve interception processing of custom annotations. Through these steps, we can use the custom annotation `@BaseGateWay` as a pointcut, enhance classes marked with this annotation in the interceptor, and register the interceptor and weave the aspect into the application through the configuration class to achieve interception processing of specific annotations, enabling more flexible business logic control.

[0065] Step S203 involves implementing a gateway-wide exception handling interceptor. Since the target of the interception is a method, the interceptor implements the `MethodInterceptor` interface for method enhancement. The input parameter is a `MethodInvocation` object, which carries aspect information such as the method being called and its parameters. Specifically, when the AOP framework detects that a target method is about to be called, it creates a `MethodInvocation` object and passes it to one or more `MethodInterceptor` instances. The `invoke()` method of each `MethodInterceptor` is called sequentially. These interceptors can choose to perform additional operations, such as logging, permission checks, and performance monitoring. If all interceptors return control (i.e., no exception is thrown), the target method is ultimately called. If the target method executes successfully, its result is returned to the caller. If the target method throws an exception, the interceptor can choose to catch and handle the exception. MethodInvocation and MethodInterceptor are two core concepts in Aspect-Oriented Programming (AOP). They primarily add extra operations before, after, or when an exception is thrown. MethodInvocation represents a callable method, containing information such as the target object, the method to be invoked, and the method parameters. Through MethodInvocation, the execution flow of a method can be controlled without directly calling the target method. The MethodInterceptor interface defines a single core method, invoke(), which accepts a MethodInvocation object as a parameter and returns a result. The main responsibility of MethodInterceptor is to intercept calls to the target method and perform additional operations before, after, or when an exception is thrown.

[0066] Step S204 implements the general output parameter conversion IacCommonResultConvert. Its core logic involves catching the custom business exception IacBizException, processing it, and returning objects such as BaseCommonResult, BaseCommonGwResult, and BaseCommonManResult, along with their corresponding status codes and message information. Here, IacCommonResultConvert is a custom result wrapper class; IacBizException is a custom business exception; and BaseCommonResult, BaseCommonGwResult, and BaseCommonManResult are all custom result encapsulation classes.

[0067] Step S205 allows for unified exception handling using `IacBaseExceptionConvert`. This converts non-business exceptions like `ExecuteFlowException` thrown by process nodes into custom system exceptions `IacSystemException`, which are then thrown by the JSF caller (JavaServer Faces, a Java server-side object-oriented framework). When integrating the code, simply annotate the implementation layer of the API (Application Programming Interface) with the `@BaseGateWay` annotation.

[0068] Standardizing and unifying exception management in code allows developers to focus solely on business logic without spending excessive time writing redundant try {} catch {} blocks. For callers, it also results in more user-friendly data responses. Overall, using interceptors for exception handling improves development efficiency, reduces maintenance costs, and contributes to enhanced code quality and application stability. In practice, interceptor functionality can be flexibly adjusted and extended to meet various exception handling needs.

[0069] According to a second aspect of the present invention, an apparatus for handling code exceptions is provided.

[0070] Figure 3 This is a schematic diagram of the main modules of a code exception handling apparatus according to an embodiment of the present invention. Figure 3 As shown, the code exception handling apparatus 300 includes:

[0071] Module 301 is defined to define custom annotations; these custom annotations are used to mark business classes that handle unified exceptions.

[0072] Configuration module 302 is used to configure interceptors with custom annotations as pointcuts and define exception handling logic in the interceptors;

[0073] The processing module 303 is used to capture the code exception information corresponding to the business class of unified exception handling using an interceptor, and to process the code exception information according to the exception handling logic.

[0074] Optionally, module 301 is also used for:

[0075] Create a custom annotation based on the obtained business keywords, and set the attributes of the custom annotation to the obtained unified exception handling business class.

[0076] Optionally, the configuration module 302 is also used for:

[0077] Configure pointcut expressions in aspect classes for aspect-oriented programming, and associate interceptors with custom annotations based on pointcut expressions.

[0078] Optionally, the code exception handling apparatus 300 further includes a modification module, which is used for:

[0079] Utilize dynamic proxy technology to configure aspect-oriented programming (AOP), enabling AOP to dynamically modify exception handling logic at runtime.

[0080] Optionally, the code exception handling apparatus 300 further includes a conversion module, which is used for:

[0081] The response object corresponding to the processing result is generated based on the predefined general output parameter conversion logic; the response object includes the status code and message information.

[0082] Optionally, the code exception handling apparatus 300 further includes a system message generation module, which is modified to:

[0083] Identify non-business exception information in the code exception information, and generate system exception messages corresponding to the system exceptions based on the non-business exception information.

[0084] It should be noted that the specific implementation of the device for handling code exceptions in this invention has been described in detail in the method for handling code exceptions above, so the content will not be repeated here.

[0085] According to a third aspect of the present invention, an electronic device is provided, comprising: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the present invention.

[0086] According to a fourth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method provided in the first aspect of the present invention.

[0087] According to a fifth aspect of the present invention, a computer program product is provided, including a computer program that, when executed by a processor, implements the method provided in the first aspect of the present invention.

[0088] Figure 4 An exemplary system architecture 400 is shown in which the method or apparatus for code exception handling of embodiments of the present invention can be applied.

[0089] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, and 403, a network 404, and a server 405. Network 404 serves as the medium for providing communication links between terminal devices 401, 402, and 403 and server 405. Network 404 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0090] Users can use terminal devices 401, 402, and 403 to interact with server 405 via network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, and 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).

[0091] Terminal devices 401, 402, and 403 can be various electronic devices with displays that support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0092] Server 405 can be a server that provides various services, such as a backend management server that supports shopping websites browsed by users using terminal devices 401, 402, and 403 (for example only). The backend management server can analyze and process data such as received product information query requests, and feed back the processing results (e.g., processing results - for example only) to the terminal devices.

[0093] It should be noted that the code exception handling method provided in the embodiments of the present invention is generally run by server 405, and correspondingly, the code exception handling device is generally set in server 405.

[0094] It should be understood that Figure 4 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0095] The following is for reference. Figure 5 It shows a schematic diagram of the structure of a computer system 500 suitable for implementing a terminal device of the present invention. Figure 5 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.

[0096] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 502 or programs loaded from storage section 508 into random access memory (RAM) 503. The RAM 503 also stores various programs and data required for the operation of the system 500. The CPU 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0097] The following components are connected to I / O interface 505: an input section 506 including a keyboard, mouse, etc.; an output section 507 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, modem, etc. The communication section 509 performs communication processing via a network such as the Internet. Drive 510 is also connected to I / O interface 505 as needed. Removable media 511, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 510 as needed so that computer programs read from them can be installed into storage section 508 as needed.

[0098] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 509, and / or installed from removable medium 511. When the computer program is run by the central processing unit (CPU) 501, it performs the functions defined above in the system of this invention.

[0099] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit programs for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0100] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more operable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually operate substantially in parallel, and they may sometimes operate in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0101] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be located in a processor; for example, a processor can be described as including a definition module, a configuration module, and a processing module. The names of these modules do not necessarily limit the module itself; for example, a definition module can also be described as "a module for defining custom annotations."

[0102] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to include: defining custom annotations; wherein the custom annotations are used to mark business classes for unified exception handling; configuring interceptors as pointcuts using the custom annotations, and defining exception handling logic in the interceptors; capturing code exception information corresponding to the business classes for unified exception handling using the interceptors, and processing the code exception information according to the exception handling logic.

[0103] The computer program product provided in this embodiment of the invention includes a computer program that, when executed by a processor, implements the code exception handling method in this embodiment of the invention.

[0104] According to the technical solution of the present invention, the following advantages or beneficial effects are achieved: by defining custom annotations; wherein, the custom annotations are used to mark the business classes of unified exception handling; the custom annotations are configured as pointcuts to interceptors, and exception handling logic is defined in the interceptors; the interceptors are used to capture the code exception information corresponding to the business classes of unified exception handling, and the code exception information is processed according to the exception handling logic; thereby simplifying the code structure, improving the readability and maintainability of the code, and improving the efficiency of exception handling.

[0105] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

[0106] It should be noted that the acquisition, storage, and application of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

Claims

1. A method for handling code exceptions, characterized in that, include: Define custom annotations; wherein, the custom annotations are used to mark business classes with unified exception handling; Configure the custom annotation as a pointcut to interceptor, and define exception handling logic in the interceptor; The interceptor is used to capture code exception information corresponding to the business class of the unified exception handling, and the code exception information is processed according to the exception handling logic.

2. The method according to claim 1, characterized in that, Define custom annotations, including: Create a custom annotation based on the obtained business keywords, and set the attributes of the custom annotation to the obtained unified exception handling business class.

3. The method according to claim 1, characterized in that, Configure the interceptor as a pointcut using the custom annotation, including: Configure pointcut expressions in aspect classes for aspect-oriented programming, and associate interceptors with custom annotations based on these pointcut expressions.

4. The method according to claim 3, characterized in that, The method further includes: Dynamic proxy technology is used to configure aspect-oriented programming so that the exception handling logic can be dynamically modified at runtime.

5. The method according to claim 1, characterized in that, After processing the code exception information according to the exception handling logic, the method further includes: A response object corresponding to the processing result is generated based on a predefined general output parameter conversion logic; wherein, the response object includes a status code and message information.

6. The method according to claim 1, characterized in that, The method further includes: Identify the non-business-related exception information in the code exception information, and generate a system exception message corresponding to the system exception based on the non-business-related exception information.

7. A device for handling code exceptions, characterized in that, include: The definition module is used to define custom annotations; wherein, the custom annotations are used to mark business classes with unified exception handling; The configuration module is used to configure the custom annotation as a pointcut to interceptor and define exception handling logic in the interceptor; The processing module is used to capture code exception information corresponding to the business class of the unified exception handling using the interceptor, and process the code exception information according to the exception handling logic.

8. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-6.

9. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-6.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-6.