Error handling method, device, equipment, medium and product based on Go language
By defining the types used to save call stack information and error information and declaring related functions, the problem of lack of call stack information in the Go language standard library is solved, efficient error handling and bug troubleshooting is achieved, and time cost is reduced.
Patent Information
- Application Number
- CN202111575980.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2024-12-20
- Estimated Expiration
- 2041-12-21
AI Technical Summary
The lack of call stack information in the Go language standard library, resulting in low efficiency in error handling and bug troubleshooting and increasing time cost.
The type of call stack information and error information is defined, and the related functions are declared to instantiate the error type, completing the output of call stack information and error information, improving compatibility and efficiency.
By encapsulating and outputting call stack information, the problem that the Go language standard library cannot directly obtain call stack information is supplemented, which significantly accelerates the efficiency and processing speed of error processing.
Smart Images

Figure CN114237624B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, specifically to the field of software systems, and more specifically to a method, apparatus, device, medium and program product for error handling based on the Go language. Background Art
[0002] When using Go language to develop software, error handling is often used. The Go language standard library does not provide call stack information for error handling. Some other languages (such as Java and PHP) usually provide error handling solutions with call stack information, which makes it very convenient to track and troubleshoot bugs. However, the error handling solution of the Go language standard library does not have call stack information, which makes it very inconvenient to track and troubleshoot bugs, resulting in high time costs. Summary of the invention
[0003] In view of the above problems, the present disclosure provides a Go language-based error handling method, apparatus, device, medium and program product that improve the error handling efficiency in a Go language development environment.
[0004] According to a first aspect of the present disclosure, there is provided an error handling method based on the Go language, comprising: defining a first type for storing call stack information, wherein the call stack information includes information obtained based on calling a first related function; defining a second type for storing call stack information error information, wherein the second type includes the first type and error information, and is used to output the call stack information and the error information at the same time; declaring a second related function, so that after the execution of the second related function is completed, the second type is returned to complete the instantiation of the error type; and based on the instantiated error type, the output of the call stack information and the error information is completed.
[0005] According to an embodiment of the present disclosure, the first type includes a slice type, and the second type includes a structure type, wherein the slice type includes multiple elements for storing multiple unsigned pointers, and each of the unsigned pointers points to a memory address storing each of the call stack information.
[0006] According to an embodiment of the present disclosure, the second related function is declared so that after the execution of the second related function, the second type is returned to instantiate the error type, wherein the second related function includes: a function name, parameter type and return type that are consistent with the third related function to improve compatibility, and the third related function includes a function in the standard library that can implement the error type.
[0007] According to an embodiment of the present disclosure, the output of the call stack information and the error information is completed based on the instantiated error type, including: based on the instantiated error type, obtaining the call stack information and the error information of the second type, the call information including first character information; formatting the first character information in the call stack to obtain second character information; and outputting the error information and the second character information.
[0008] A second aspect of the present disclosure provides an error handling device based on the Go language, including: a first type definition module, a second type first module, a function declaration module and an output module; wherein the first type definition module is used to define a first type for saving call stack information, wherein the call stack information includes information obtained based on calling a first related function; the second type definition module is used to define a second type for saving call stack information error information, the second type includes the first type and error information, and is used to output the call stack information and the error information at the same time; the function declaration module is used to declare a second related function, so that after the execution of the second related function is completed, the second type is returned to complete the instantiation of the error type; and the output module is used to complete the output of the call stack information and the error information based on the instantiated error type.
[0009] According to an embodiment of the present disclosure, the first type includes a slice type, and the second type includes a structure type, wherein the slice type includes multiple elements for storing multiple unsigned pointers, and each of the unsigned pointers points to a memory address storing each of the call stack information.
[0010] According to an embodiment of the present disclosure, the second related function is declared so that after the execution of the second related function, the second type is returned to instantiate the error type, wherein the second related function includes: a function name, parameter type and return type that are consistent with the third related function to improve compatibility, and the third related function includes a function in the standard library that can implement the error type.
[0011] According to an embodiment of the present disclosure, the output module includes: an acquisition unit, a formatting unit and an output unit; wherein the acquisition unit is used to acquire the call stack information of the second type and the error information based on the instantiated error type, and the call information includes the first character information;
[0012] The formatting unit is used to format the first character information in the call stack to obtain the second character information; and the output unit is used to output the error information and the second character information.
[0013] A third aspect of the present disclosure provides an electronic device, comprising: one or more processors; and a memory 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 execute the above-mentioned error handling method based on the Go language.
[0014] The fourth aspect of the present disclosure also provides a computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to execute the above-mentioned error handling method based on the Go language.
[0015] The fifth aspect of the present disclosure also provides a computer program product, including a computer program, which implements the above-mentioned error handling method based on the Go language when executed by a processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The above contents and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:
[0017] Figure 1 An application scenario diagram schematically illustrates an error handling method, apparatus, device, medium, and program product based on the Go language according to an embodiment of the present disclosure;
[0018] Figure 2 A flowchart of an error handling method of the Go language according to an embodiment of the present disclosure is schematically shown;
[0019] Figure 3 A flowchart of a method for outputting call stack information according to an embodiment of the present disclosure is schematically shown;
[0020] Figure 4 A structural block diagram of an error handling device based on the Go language according to an embodiment of the present disclosure is schematically shown; and
[0021] Figure 5 A block diagram of an electronic device suitable for implementing an error handling method based on the Go language according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0022] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.
[0023] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.
[0024] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification, and should not be interpreted in an idealized or overly rigid manner.
[0025] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).
[0026] When using Go language to develop software, error handling is often used. The Go language standard library does not provide call stack information for error handling. Some other languages (such as Java and PHP) usually provide error handling solutions with call stack information, which makes it very convenient to track and troubleshoot bugs. However, the error handling solution of the Go language standard library does not have call stack information, which makes it very inconvenient to track and troubleshoot bugs, resulting in high time costs.
[0027] An embodiment of the present disclosure provides an error handling method based on the Go language, which is applied in a development environment of the Go language, and includes: defining a first type for saving call stack information, wherein the call stack information includes information obtained based on calling a first related function; defining a second type for saving call stack information error information, wherein the second type includes the first type and error information, and is used to output the call stack information and the error information at the same time; declaring a second related function, so that after the execution of the second related function is completed, the second type is returned to complete the instantiation of the error type; and based on the instantiated error type, the output of the call stack information and the error information is completed.
[0028] The embodiments of the present disclosure achieve the simultaneous output of error information and call stack information by encapsulating and outputting call stack information, which makes up for the problem in the prior art that the standard library based on the Go language cannot directly obtain call stack information and perform error handling, thereby speeding up the efficiency and speed of error handling in actual development and testing.
[0029] Figure 1 An application scenario diagram of error handling based on the Go language according to an embodiment of the present disclosure is schematically shown.
[0030] like Figure 1 As shown, the application scenario 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for a communication link between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0031] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0032] The terminal devices 101 , 102 , and 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0033] The server 105 may be a server that provides various services, such as a background management server (only an example) that provides support for websites browsed by users using the terminal devices 101, 102, and 103. The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.
[0034] It should be noted that the Go language-based error handling method provided in the embodiment of the present disclosure can generally be executed by the server 105. Accordingly, the Go language-based error handling device provided in the embodiment of the present disclosure can generally be set in the server 105. The Go language-based error handling method provided in the embodiment of the present disclosure can also be executed by a server or server cluster that is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and / or the server 105. Correspondingly, the Go language-based error handling device provided in the embodiment of the present disclosure can also be set in a server or server cluster that is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and / or the server 105.
[0035] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0036] The following will be based on Figure 1 The scene described by Figure 2-3 The error handling method based on Go language of the disclosed embodiment is described in detail.
[0037] Figure 2 The flowchart of the error handling method based on the Go language according to an embodiment of the present disclosure is schematically shown.
[0038] like Figure 2 As shown, the error handling method based on the Go language of this embodiment includes operations S210 to S240, and the transaction processing method can be executed by the server 105.
[0039] In operation S210, a first type is defined to store call stack information, wherein the call stack information is obtained based on calling a first related function.
[0040] There are many data types in Go language. In addition to the basic integer, floating point, Boolean, and string types, there are also arrays, slices, structures, functions, maps, channels, etc. In Go language, data types are used to declare functions and variables. The emergence of data types is to divide data into data of different memory sizes. When large data is needed for storage, large memory is requested to make full use of memory.
[0041] According to an embodiment of the present disclosure, the first type includes a slice type. The slice type in the Go language is an abstraction based on the array type. Compared with an array, a slice only stores information such as the pointer, length, and capacity of the original array. Its length is not fixed, and a portion of the array can be intercepted as a slice, so that the slice type can also achieve dynamic expansion.
[0042] According to an embodiment of the present disclosure, the slice type includes multiple elements for storing multiple unsigned pointers, and each of the unsigned pointers points to a memory address storing each of the call stack information.
[0043] For example, the first type defined is a slice type stack, and an unsigned pointer uintptr is used to point to the call stack information. The call stack information is collected using the Callers function in the runtime environment. The Callers function is the first related function, the runtime.Callers function in the Go language, which mainly returns the function call stack information. Among them, the runtime environment package is a library function in the Go language. The runtime is responsible for interacting with the underlying operating system, and the Callers function in the runtime environment obtains the call stack information. Finally, a type st is defined to save the call stack information and return the address of st.
[0044] It should be noted that the slice type in the Go language includes multiple elements. Unsigned pointers are saved in the slice type. An unsigned pointer is saved at the position of each element. The address of the call stack information is accessed through the unsigned pointer. This saves the memory space required to save the call stack information and improves the utilization rate of the call stack.
[0045] In operation S220, a second type is defined for storing call stack information and error information, where the second type includes the first type and error information, and is used to output the call stack information and the error information simultaneously.
[0046] According to an embodiment of the present disclosure, the second type includes a structure type. In the Go language, a structure is a user-defined type, which is an aggregated data type, an entity aggregated from zero or more values of any type. Each value becomes a member of the structure.
[0047] For example, define a structure to save error information and call stack information, name the structure fund, and include the error message string msg and call stack information stack.
[0048] In operation S230, a second related function is declared, so that after the execution of the second related function is completed, the second type is returned to complete the instantiation of the error type.
[0049] According to an embodiment of the present disclosure, the second related function includes: a function name, parameter type and return type that are consistent with the third related function to improve compatibility, and the third related function includes a function in a standard library that can implement the error type.
[0050] Most of the time, instantiating an object means allocating memory space for the object.
[0051] For example, the second related functions declared this time may include: New function and Errorf function. Among them, the New function is used to return a pointer to a fund structure as an error, which includes string information and a call stack; the Errorf function returns a pointer to a fund structure as an error, which includes string information and a call stack. The New function and the Errorf function are used in different application scenarios.
[0052] Specifically, the function name, parameter type and return type in the New function and the Errorf function are consistent with the third related function New and Errorf in the standard library. It should be noted that the third related function in the standard library. The above error is the error type, and it is necessary to instantiate the error by returning the second type (i.e., the structure fund) through the function, allocate memory space, and mainly return call information and other parameters, and other parameters can be error information. However, the New function and the Errorf function of the above second related function have different parameters, so different functions are used in different implementation environments.
[0053] In the embodiment of the present disclosure, by declaring the second related function, the function name, parameter type and return type are kept consistent with those of the third related function in the standard library, so that the function we declare has the same strong generalization ability as the function in the standard library, and the error handling method based on the Go language disclosed in the present disclosure has rich application scenarios.
[0054] In operation S240, based on the instantiated error type, the call stack information and the error information are output.
[0055] The embodiments of the present disclosure achieve the simultaneous output of error information and call stack information by encapsulating and outputting call stack information, which makes up for the problem in the prior art that the standard library based on the Go language cannot directly obtain call stack information and perform error handling, thereby speeding up the efficiency and speed of error handling in actual development and testing.
[0056] Figure 3 The flowchart of the method for outputting call stack information according to an embodiment of the present disclosure is schematically shown.
[0057] like Figure 3 As shown, the call stack information output method of this embodiment includes operations S310 to S330, and the transaction processing method can be executed by the server 105.
[0058] In operation S310, based on the instantiated error type, call stack information of the second type and the error information are acquired, where the call information includes first character information.
[0059] In operation S320, the first character information in the call stack is formatted to obtain second character information.
[0060] In operation S330, the error information and the second character information are output.
[0061] For example, the Error function is used to output error information in a scenario where only error information needs to be output. The Format function is used to format the call stack information, and the call stack information, that is, the first character information, is printed as recognizable second character information.
[0062] In the embodiment of the present disclosure, the unrecognizable first character information is formatted and converted into recognizable second character information, and then output for viewing by the user.
[0063] Based on the above Go language-based error handling method, the present disclosure also provides a Go language-based error handling device. Figure 4 The device is described in detail.
[0064] Figure 4 The structural block diagram of the error handling device based on the Go language according to an embodiment of the present disclosure is schematically shown.
[0065] like Figure 4 As shown, the Go language-based error handling device 400 of this embodiment includes a first type definition module 410 , a second type first module 420 , a function declaration module 430 and an output module 440 .
[0066] The first type definition module 410 is used to define a first type for storing call stack information, wherein the call stack information includes information obtained based on calling a first related function. In one embodiment, the first type definition module 410 can be used to perform the operation S210 described above, which will not be described in detail here.
[0067] The second type definition module 420 is used to define a second type for storing call stack information error information, the second type includes the first type and error information, and is used to output the call stack information and the error information at the same time. In one embodiment, the second type definition module 420 can be used to perform the operation S220 described above, which will not be repeated here.
[0068] The function declaration module 430 is used to declare the second related function, so that after the second related function is executed, the second type is returned to complete the instantiation of the error type. In one embodiment, the function declaration module 430 can be used to perform the operation S230 described above, which will not be repeated here.
[0069] The output module 440 is used to output the call stack information and the error information based on the instantiated error type. In one embodiment, the output module 440 can be used to perform the operation S240 described above, which will not be described in detail here.
[0070] According to an embodiment of the present disclosure, the first type includes a slice type, and the second type includes a structure type, wherein the slice type includes multiple elements for storing multiple unsigned pointers, and each of the unsigned pointers points to a memory address storing each of the call stack information.
[0071] According to an embodiment of the present disclosure, the second related function is declared so that after the execution of the second related function, the second type is returned to instantiate the error type, wherein the second related function includes: a function name, parameter type and return type that are consistent with the third related function to improve compatibility, and the third related function includes a function in the standard library that can implement the error type.
[0072] According to an embodiment of the present disclosure, the output module includes: an acquisition unit, a formatting unit and an output unit; wherein the acquisition unit is used to acquire the call stack information and the error information of the second type based on the instantiated error type, and the call information includes first character information; the formatting unit is used to format the first character information in the call stack to obtain second character information; and the output unit is used to output the error information and the second character information.
[0073] According to an embodiment of the present disclosure, any multiple modules of the first type definition module 410, the second type first module 420, the function declaration module 430 and the output module 440 can be combined in one module for implementation, or any one of the modules can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of the first type definition module 410, the second type first module 420, the function declaration module 430 and the output module 440 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in a suitable combination of any of them. Alternatively, at least one of the first type definition module 410, the second type first module 420, the function declaration module 430 and the output module 440 may be at least partially implemented as a computer program module, which may perform a corresponding function when executed.
[0074] Figure 5A block diagram of an electronic device suitable for implementing an error handling method based on the Go language according to an embodiment of the present disclosure is schematically shown.
[0075] like Figure 5 As shown, the electronic device 500 according to an embodiment of the present disclosure includes a processor 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. The processor 501 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 501 may also include an onboard memory for caching purposes. The processor 501 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.
[0076] In RAM 503, various programs and data required for the operation of electronic device 500 are stored. Processor 501, ROM 502 and RAM 503 are connected to each other via bus 504. Processor 501 performs various operations of the method flow according to the embodiment of the present disclosure by executing the program in ROM 502 and / or RAM 503. It should be noted that the program can also be stored in one or more memories other than ROM 502 and RAM 503. Processor 501 can also perform various operations of the method flow according to the embodiment of the present disclosure by executing the program stored in the one or more memories.
[0077] According to an embodiment of the present disclosure, the electronic device 500 may further include an input / output (I / O) interface 505, which is also connected to the bus 504. The electronic device 500 may further include one or more of the following components connected to the I / O interface 505: an input portion 506 including a keyboard, a mouse, etc.; an output portion 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 508 including a hard disk, etc.; and a communication portion 509 including a network interface card such as a LAN card, a modem, etc. The communication portion 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage portion 508 as needed.
[0078] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present disclosure is implemented.
[0079] According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device. For example, according to an embodiment of the present disclosure, a computer-readable storage medium may include the ROM 502 and / or RAM 503 described above and / or one or more memories other than ROM 502 and RAM 503.
[0080] The embodiment of the present disclosure also includes a computer program product, which includes a computer program, and the computer program contains program code for executing the method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to enable the computer system to implement the item recommendation method provided by the embodiment of the present disclosure.
[0081] The above functions defined in the system / device of the embodiment of the present disclosure are performed when the computer program is executed by the processor 501. According to the embodiment of the present disclosure, the system, device, module, unit, etc. described above can be implemented by a computer program module.
[0082] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices, magnetic storage devices, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of signals on a network medium, and downloaded and installed through the communication part 509, and / or installed from the removable medium 511. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0083] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the processor 501, the above functions defined in the system of the embodiment of the present disclosure are performed. According to the embodiment of the present disclosure, the system, device, means, module, unit, etc. described above can be implemented by a computer program module.
[0084] According to an embodiment of the present disclosure, the program code for executing the computer program provided by the embodiment of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet).
[0085] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0086] It will be appreciated by those skilled in the art that the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways, even if such combinations and / or combinations are not explicitly described in the present disclosure. In particular, the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways without departing from the spirit and teachings of the present disclosure. All of these combinations and / or combinations fall within the scope of the present disclosure.
[0087] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. The scope of the present disclosure is defined by the attached claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.
Claims
1. An error handling method based on Go language, characterized in that: The method is applied in a Go language development environment, and the method includes: A first type is defined to store call stack information, wherein the call stack information includes information obtained based on calling a first related function; defining a second type for storing call stack information and error information, wherein the second type includes the first type and error information, and is used for outputting the call stack information and the error information simultaneously; Declare a second related function, so that after the execution of the second related function is completed, the second type is returned to complete the instantiation of the error type; and Based on the instantiated error type, outputting the call stack information and the error information; The first type includes a slice type, and the second type includes a structure type, wherein the slice type includes a plurality of elements for storing a plurality of unsigned pointers, and each of the unsigned pointers points to a memory address storing each of the call stack information; The declaration of the second related function returns the second type to instantiate the error type after the execution of the second related function is completed, wherein the second related function includes: a function name, parameter type and return type that are consistent with the third related function to improve compatibility, and the third related function includes a function in the standard library that can implement the error type.
2. The method according to claim 1, characterized in that The outputting of the call stack information and the error information based on the instantiated error type includes: Based on the instantiated error type, acquiring call stack information of the second type and the error information, wherein the call stack information includes first character information; Formatting the first character information in the call stack to obtain second character information; and The error information and the second character information are output.
3. An error handling device based on Go language, characterized in that: The device comprises: a first type definition module, a second type first module, a function declaration module and an output module; in, The first type definition module is used to define a first type for storing call stack information, wherein the call stack information includes information obtained based on calling a first related function; The second type definition module is used to define a second type for storing call stack information error information, the second type includes the first type and error information, and is used to output the call stack information and the error information at the same time; The function declaration module is used to declare a second related function, so that after the execution of the second related function is completed, the second type is returned to complete the instantiation of the error type; and An output module, used for outputting the call stack information and the error information based on the instantiated error type; The first type includes a slice type, and the second type includes a structure type, wherein the slice type includes a plurality of elements for storing a plurality of unsigned pointers, and each of the unsigned pointers points to a memory address storing each of the call stack information; The declaration of the second related function returns the second type to instantiate the error type after the execution of the second related function is completed, wherein the second related function includes: a function name, parameter type and return type that are consistent with the third related function to improve compatibility, and the third related function includes a function in the standard library that can implement the error type.
4. The device according to claim 3, characterized in that The output module includes: an acquisition unit, a formatting unit and an output unit; in, The acquiring unit is configured to acquire call stack information of the second type and the error information based on the instantiated error type, wherein the call stack information includes first character information; The formatting unit is used to format the first character information in the call stack to obtain second character information; and The output unit is used to output the error information and the second character information.
5. An electronic device, comprising: one or more processors; a 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 are enabled to execute the method according to any one of claims 1 to 2.
6. A computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to execute the method according to any one of claims 1 to 2.
7. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 2 is implemented.
