Movatterモバイル変換


[0]ホーム

URL:


CN114237624B - Error handling method, device, equipment, medium and product based on Go language - Google Patents

Error handling method, device, equipment, medium and product based on Go language
Download PDF

Info

Publication number
CN114237624B
CN114237624BCN202111575980.4ACN202111575980ACN114237624BCN 114237624 BCN114237624 BCN 114237624BCN 202111575980 ACN202111575980 ACN 202111575980ACN 114237624 BCN114237624 BCN 114237624B
Authority
CN
China
Prior art keywords
type
information
error
call stack
related function
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111575980.4A
Other languages
Chinese (zh)
Other versions
CN114237624A (en
Inventor
徐强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CCB Finetech Co Ltd
Original Assignee
CCB Finetech Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by CCB Finetech Co LtdfiledCriticalCCB Finetech Co Ltd
Priority to CN202111575980.4ApriorityCriticalpatent/CN114237624B/en
Publication of CN114237624ApublicationCriticalpatent/CN114237624A/en
Application grantedgrantedCritical
Publication of CN114237624BpublicationCriticalpatent/CN114237624B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Classifications

Landscapes

Abstract

Translated fromChinese

本公开提供了一种基于Go语言的错误处理方法,可以应用于计算机技术领域。该基于Go语言的错误处理方法包括:定义第一类型用以保存调用栈信息,其中,所述调用栈信息包括基于调用第一相关函数得到;定义第二类型用以保存调用栈信息错误信息,所述第二类型包括所述第一类型和错误信息,用于同时输出所述调用栈信息和所述错误信息;声明第二相关函数,使得在所述第二相关函数执行结束后,返回所述第二类型以完成对错误类型的实例化;以及基于实例化后的所述错误类型,完成对所述调用栈信息和所述错误信息的输出。本公开还提供了一种基于Go语言的错误处理装置、设备、存储介质和程序产品。

The present disclosure provides an error handling method based on the Go language, which can be applied to the field of computer technology. The error handling method based on the Go language includes: defining a first type to save call stack information, wherein the call stack information includes information obtained based on calling a first related function; defining a second type to save 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; declaring a second related function, so that after the execution of the second related function ends, 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. The present disclosure also provides an error handling device, equipment, storage medium and program product based on the Go language.

Description

Error processing method, device, equipment, medium and product based on Go language
Technical Field
The present disclosure relates to the field of computer technology, and more particularly, to a method, apparatus, device, medium, and program product for Go language-based error handling.
Background
In the process of developing software by using the Go language, error processing is often required, call stack information for error processing is not provided in a standard library of the Go language, and other languages (such as java and php) generally have error processing schemes for providing the call stack information, so that bug tracking and checking become very convenient. The error processing scheme of the Go language standard library is that no call stack information is used, so that the bug is very inconvenient to track and check, and the time cost is high.
Disclosure of Invention
In view of the foregoing, the present disclosure provides a GO language-based error processing method, apparatus, device, medium, and program product that improve the efficiency of error processing in a GO language development environment.
According to a first aspect of the disclosure, an error processing method based on a Go language is provided, which comprises defining a first type to store call stack information, wherein the call stack information is obtained based on calling a first related function, defining a second type to store call stack information error information, wherein the second type comprises the first type and the error information and is used for simultaneously outputting the call stack information and the error information, declaring a second related function, so that after the execution of the second related function is finished, the second type is returned to complete the instantiation of the error type, and completing the output of the call stack information and the error information based on the instantiated error type.
According to an embodiment of the disclosure, the first type includes a slice type and the second type includes a structure type, wherein the slice type includes a plurality of elements to hold a plurality of unsigned pointers, each of the unsigned pointers pointing to a memory address holding each of the call stack information.
According to the embodiment of the disclosure, the second correlation function is declared, so that after the execution of the second correlation function is finished, the second type is returned to instantiate the error type, wherein the second correlation function comprises a function name, a parameter type and a return type which are consistent with a third correlation function to improve compatibility, and the third correlation function comprises a function capable of realizing the error type in a standard library.
According to the embodiment of the disclosure, the outputting of the call stack information and the error information is completed based on the instantiated error type, and the method comprises the steps of obtaining call stack information and the error information of the second type based on the instantiated error type, wherein the call information comprises 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.
The second aspect of the disclosure provides an error processing device based on a Go language, which comprises 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 for defining a first type to store call stack information, the call stack information is obtained based on calling a first related function, the second type definition module is used for defining a second type to store call stack information error information, the second type includes the first type and the error information and is used for outputting the call stack information and the error information at the same time, the function declaration module is used for declaring a second related function, so that after the execution of the second related function is finished, the second type is returned to complete the instantiation of the error type, and the output module is used for completing the output of the call stack information and the error information based on the instantiated error type.
According to an embodiment of the disclosure, the first type includes a slice type and the second type includes a structure type, wherein the slice type includes a plurality of elements to hold a plurality of unsigned pointers, each of the unsigned pointers pointing to a memory address holding each of the call stack information.
According to the embodiment of the disclosure, the second correlation function is declared, so that after the execution of the second correlation function is finished, the second type is returned to instantiate the error type, wherein the second correlation function comprises a function name, a parameter type and a return type which are consistent with a third correlation function to improve compatibility, and the third correlation function comprises a function capable of realizing the error type in a standard library.
The output module comprises an acquisition unit, a formatting unit and an output unit, wherein the acquisition unit is used for acquiring the call stack information of the second type and the error information based on the instantiated error type, and the call information comprises first character information;
The system comprises a call stack, a formatting unit used for formatting the first character information in the call stack to obtain second character information, and an output unit used for outputting the error information and the second character information.
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 the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the Go language-based error handling method described above.
A fourth aspect of the present disclosure also provides a computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to perform the above-described Go language-based error handling method.
A fifth aspect of the present disclosure also provides a computer program product comprising a computer program which, when executed by a processor, implements the above-described Go language-based error handling method.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be more apparent from the following description of embodiments of the disclosure with reference to the accompanying drawings, in which:
FIG. 1 schematically illustrates an application scenario diagram of a Go language-based error handling method, apparatus, device, medium, and program product according to an embodiment of the present disclosure;
FIG. 2 schematically illustrates a flow chart of an error handling method for the Go language according to an embodiment of the present disclosure;
FIG. 3 schematically illustrates a flow chart of a call stack information output method according to an embodiment of the disclosure;
FIG. 4 schematically shows a block diagram of an error handling apparatus based on the Go language according to an embodiment of the present disclosure, and
Fig. 5 schematically illustrates a block diagram of an electronic device adapted to implement an error handling method based on the Go language, according to an embodiment of the disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is only exemplary and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the present disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. In addition, in the following description, descriptions of well-known structures and techniques are omitted so as not to unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and/or the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It should be noted that the terms used herein should be construed to have meanings consistent with the context of the present specification and should not be construed in an idealized or overly formal manner.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a convention should be interpreted in accordance with the meaning of one of skill in the art having generally understood the convention (e.g., "a system having at least one of A, B and C" would include, but not be limited to, systems having a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
In the process of developing software by using the Go language, error processing is often required, call stack information for error processing is not provided in a standard library of the Go language, and other languages (such as java and php) generally have error processing schemes for providing the call stack information, so that bug tracking and checking become very convenient. The error processing scheme of the Go language standard library is that no call stack information is used, so that the bug is very inconvenient to track and check, and the time cost is high.
The embodiment of the disclosure provides an error processing method based on a Go language, which is applied to a development environment of the Go language, and comprises the steps of defining a first type to store call stack information, wherein the call stack information is obtained based on calling a first related function, defining a second type to store call stack information error information, the second type comprises the first type and the error information and is used for simultaneously outputting the call stack information and the error information, declaring a second related function, and returning the second type to complete instantiation of the error type after execution of the second related function is finished, and completing output of the call stack information and the error information based on the instantiated error type.
According to the embodiment of the disclosure, the package and the output of the call stack information are performed, so that the simultaneous output of the error information and the call stack information is completed, the problem that the call stack information cannot be directly acquired and the error processing cannot be performed by a standard library based on the Go language in the prior art is solved, and the efficiency and the processing speed of the error processing in the actual development test are improved.
Fig. 1 schematically illustrates an application scenario diagram of Go language-based error handling according to an embodiment of the present disclosure.
As shown in fig. 1, an 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 as a medium to provide communication links 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 fiber optic cables, among others.
The user may interact with the server 105 via the network 104 using the terminal devices 101, 102, 103 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 101, 102, 103.
The terminal devices 101, 102, 103 may be a variety of electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (by way of example only) providing support for websites browsed by users using the terminal devices 101, 102, 103. The background management server may analyze and process the received data such as the user request, and feed back the processing result (e.g., the web page, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that, the error processing method based on Go language provided in the embodiments of the present disclosure may be generally executed by the server 105. Accordingly, the Go language-based error handling apparatus provided by the embodiments of the present disclosure may be generally provided in the server 105. The Go language-based error handling method provided by the embodiments of the present disclosure may also be performed by a server or server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the error handling apparatus based on Go language provided by the embodiments of the present disclosure may also be provided in a server or a server cluster different from the server 105 and capable of communicating with the terminal devices 101, 102, 103 and/or the server 105.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The error processing method based on Go language of the disclosed embodiment will be described in detail with reference to fig. 2 to 3 based on the scenario described in fig. 1.
Fig. 2 schematically illustrates a flowchart of an error handling method based on Go language according to an embodiment of the present disclosure.
As shown in fig. 2, the error processing method based on Go language of this embodiment includes operations S210 to S240, and the transaction processing method may be executed by the server 105.
In operation S210, a first type is defined to store call stack information, wherein the call stack information includes a result based on calling a first related function.
The Go language has rich data types, and besides basic integer, floating point, boolean, character strings, arrays, slices, structures, functions, maps, channels, etc. In the Go language, data types are used to declare functions and variables. The data type is to divide the data into data with different memory sizes, and the large memory is applied when the large data is needed for storage, so that the memory is fully utilized.
According to an embodiment of the present disclosure, the first type includes a slice type. Slice type in Go language is an abstraction built on array type paper. Compared with the array, the slice only stores the information of the pointer, the length, the capacity and the like of the original array, the length of the slice is not fixed, and a part of the slice can be cut out from the array to be used as the slice, so that the dynamic expansion can be realized by adopting the slice type.
According to an embodiment of the present disclosure, the slice type includes a plurality of elements to hold a plurality of unsigned pointers, for each of which point to a memory address holding each of the call stack information.
For example, the first type defined is slice type stack, using unsigned pointer uintptr to call stack information. The call stack information is collected by Callers functions in runtime environments, callers functions are the first related functions, and run.callers functions in Go language are mainly used for returning the function call stack information. Wherein runtime environment package is a library function in Go language, runtime is responsible for interacting with the underlying operating system, callers functions in runtime environment get call stack information. Finally, a type st is defined for saving call stack information and returning the address of the st.
It should be noted that, the slice type in the Go language includes a plurality of elements, the unsigned pointers are stored in the slice type, the position of each element stores one unsigned pointer, and the address of the call stack information is accessed through the unsigned pointer, so that the memory space required for storing the call stack information is saved, and the utilization rate of the call stack is improved.
In operation S220, a second type is defined to store call stack information error information, the second type including the first type and the error information for simultaneously outputting the call stack information and the error information.
According to an embodiment of the present disclosure, the second type comprises a structural type. In the Go language, the structure is a type that is user-defined, is an aggregated data type, and is an entity that is aggregated from zero or more arbitrary types of values. Each value becomes a member of the structure.
For example, a structure is defined for storing error information and call stack information, and the structure is named fund, including a string msg of error information and call stack information stack.
In operation S230, a second correlation function is declared such that after the second correlation function execution ends, the second type is returned to complete the instantiation of the error type.
According to the embodiment of the disclosure, the second correlation function comprises a function name, a parameter type and a return type of a third correlation function to be consistent so as to improve compatibility, wherein the third correlation function comprises a function capable of realizing the error type in a standard library.
Most of the time, instantiating an object opens up memory space for the object.
For example, the second correlation function of the present statement may include a New function and a Errorf function. The New function is used for returning a fund structural body pointer which is taken as error and contains character string information and a call stack, and the Errorf function is used for returning a fund structural body pointer which is taken as error and contains character string information and a call stack. The New function and Errorf functions are applied to different application scenarios.
Specifically, the function names, parameter types, and return types in the New and Errorf functions are kept consistent with the third related functions New and Errorf in the standard library. It should be noted that, the third correlation function in the standard library. The error is the error type, and needs to be instantiated by returning a function to the second type (i.e. the structure fund), and memory space is allocated, and mainly call information and other parameters are returned, where the other parameters may be error information. The New function and Errorf function of the second correlation function are different due to the different parameters, so that different functions are adopted in different implementation environments.
Embodiments of the present disclosure maintain function names, parameter types, and return types consistent with a third correlation function in a standard library by declaring the second correlation function. The function stated by the user has the same strong generalization capability as the function in the standard library, so that the Go language-based error processing method disclosed by the invention is rich in application scenes.
In operation S240, outputting the call stack information and the error information is completed based on the instantiated error type.
According to the embodiment of the disclosure, the package and the output of the call stack information are performed, so that the simultaneous output of the error information and the call stack information is completed, the problem that the call stack information cannot be directly acquired and the error processing cannot be performed by a standard library based on the Go language in the prior art is solved, and the efficiency and the processing speed of the error processing in the actual development test are improved.
Fig. 3 schematically illustrates a flowchart of a call stack information output method according to an embodiment of the present disclosure.
As shown in fig. 3, the call stack information output method of this embodiment includes operations S310 to S330, and the transaction processing method may be executed by the server 105.
In operation S310, call stack information of the second type and the error information are acquired based on the instantiated error type, the call information including first character information.
In operation S320, the first character information in the call stack is formatted to obtain second character information.
In operation S330, the error information and the second character information are output.
For example, an Error function is used to output Error information in a scenario where only Error information needs to be output. And using a Format function to Format call stack information, and printing the call stack information, namely the first character information, into identifiable second character information.
In the embodiment of the disclosure, after the unrecognizable first character information is formatted and converted into the recognizable second character information, the recognizable second character information is output for the user to check.
Based on the error processing method based on the Go language, the disclosure also provides an error processing device based on the Go language. The device will be described in detail below in connection with fig. 4.
Fig. 4 schematically shows a block diagram of an error handling apparatus based on Go language according to an embodiment of the present disclosure.
As shown in fig. 4, the Go language-based error processing apparatus 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.
The first type definition module 410 is configured to define a first type to store call stack information, where the call stack information is obtained based on calling a first related function. In an embodiment, the first type definition module 410 may be configured to perform the operation S210 described above, which is not described herein.
The second type definition module 420 is configured to define a second type for storing call stack information error information, where the second type includes the first type and the error information, and is configured to output the call stack information and the error information at the same time. In an embodiment, the second type definition module 420 may be configured to perform the operation S220 described above, which is not described herein.
The function declaration module 430 is configured to declare a second correlation function, so that after execution of the second correlation function ends, the second type is returned to complete instantiation of the error type. In an embodiment, the function declaration module 430 may be configured to perform the operation S230 described above, which is not described herein.
The output module 440 is configured to complete outputting the call stack information and the error information based on the instantiated error type. In an embodiment, the output module 440 may be configured to perform the operation S240 described above, which is not described herein.
According to an embodiment of the disclosure, the first type includes a slice type and the second type includes a structure type, wherein the slice type includes a plurality of elements to hold a plurality of unsigned pointers, each of the unsigned pointers pointing to a memory address holding each of the call stack information.
According to the embodiment of the disclosure, the second correlation function is declared, so that after the execution of the second correlation function is finished, the second type is returned to instantiate the error type, wherein the second correlation function comprises a function name, a parameter type and a return type which are consistent with a third correlation function to improve compatibility, and the third correlation function comprises a function capable of realizing the error type in a standard library.
The output module comprises an acquisition unit, a formatting unit and an output unit, wherein the acquisition unit is used for acquiring call stack information of the second type and the error information based on the instantiated error type, the call information comprises first character information, the formatting unit is used for carrying out formatting processing on the first character information in the call stack to obtain second character information, and the output unit is used for outputting the error information and the second character information.
According to an embodiment of the present disclosure, any 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 combined in one module to be implemented, or any of the modules may be split into a plurality of modules. Or at least some of the functionality of one or more of the modules may be combined with, and implemented in, at least some of the functionality of other modules. According to embodiments 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 may be implemented at least in part as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system-on-chip, a system-on-substrate, a system-on-package, an Application Specific Integrated Circuit (ASIC), or in hardware or firmware, such as any other reasonable manner of integrating or packaging the circuits, or in any one of or a suitable combination of three of software, hardware, and firmware. Or 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 that, when executed, performs the corresponding function.
Fig. 5 schematically illustrates a block diagram of an electronic device adapted to implement an error handling method based on the Go language, according to an embodiment of the disclosure.
As shown in fig. 5, an electronic device 500 according to an embodiment of the present disclosure includes a processor 501 that 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 section 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 an associated chipset and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), or the like. The processor 501 may also include on-board memory for caching purposes. The processor 501 may comprise a single processing unit or a plurality of processing units for performing different actions of the method flows according to embodiments of the disclosure.
In the RAM 503, various programs and data required for the operation of the electronic apparatus 500 are stored. The processor 501, ROM 502, and RAM 503 are connected to each other by a bus 504. The processor 501 performs various operations of the method flow according to the embodiments of the present disclosure by executing programs in the ROM 502 and/or the RAM 503. Note that the program may be stored in one or more memories other than the ROM 502 and the RAM 503. The processor 501 may also perform various operations of the method flow according to embodiments of the present disclosure by executing programs stored in the one or more memories.
According to an embodiment of the present disclosure, the electronic device 500 may also include an input/output (I/O) interface 505, the input/output (I/O) interface 505 also being connected to the bus 504. The electronic device 500 may also include one or more of 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 speaker, 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., connected to the I/O interface 505. The communication section 509 performs communication processing via a network such as the internet. The 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, or the like is mounted on the drive 510 as needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
The present disclosure also provides a computer-readable storage medium that may be included in the apparatus/device/system described in the above embodiments, or may exist alone without being assembled into the apparatus/device/system. The computer-readable storage medium carries one or more programs which, when executed, implement methods in accordance with embodiments of the present disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example, but is not limited to, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, the computer-readable storage medium may include ROM 502 and/or RAM 503 and/or one or more memories other than ROM 502 and RAM 503 described above.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowcharts. The program code, when executed in a computer system, causes the computer system to implement the item recommendation method provided by embodiments of the present disclosure.
The above-described functions defined in the system/apparatus of the embodiments of the present disclosure are performed when the computer program is executed by the processor 501. The systems, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
In one embodiment, the computer program may be based on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted, distributed, and downloaded and installed in the form of a signal on a network medium, and/or installed from a removable medium 511 via the communication portion 509. The computer program may comprise program code that is transmitted using any appropriate network medium, including but not limited to wireless, wireline, etc., or any suitable combination of the preceding.
In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511. The above-described functions defined in the system of the embodiments of the present disclosure are performed when the computer program is executed by the processor 501. The systems, devices, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
According to embodiments of the present disclosure, program code for performing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, such computer programs may be implemented in high-level procedural and/or object-oriented programming languages, and/or assembly/machine languages. Programming languages include, but are not limited to, such as Java, c++, python, "C" or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., connected via the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that the features recited in the various embodiments of the disclosure and/or in the claims may be provided in a variety of combinations and/or combinations, even if such combinations or combinations are not explicitly recited in the disclosure. In particular, the features recited in the various embodiments of the present disclosure and/or the claims may be variously combined and/or combined without departing from the spirit and teachings of the present disclosure. All such combinations and/or combinations fall within the scope of the present disclosure.
The embodiments of the present disclosure are described above. These examples are for illustrative purposes only 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 embodiments cannot be used advantageously in combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be made by those skilled in the art without departing from the scope of the disclosure, and such alternatives and modifications are intended to fall within the scope of the disclosure.

Claims (7)

Translated fromChinese
1.一种基于Go语言的错误处理方法,其特征在于,所述方法应用于Go语言的开发环境中,所述方法包括:1. An error handling method based on Go language, characterized in that the method is applied in a development environment of Go language, and the method comprises:定义第一类型用以保存调用栈信息,其中,所述调用栈信息包括基于调用第一相关函数得到;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.根据权利要求1所述的方法,其特征在于,所述基于实例化后的所述错误类型,完成对所述调用栈信息和所述错误信息的输出,包括: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 comprises:基于实例化后的所述错误类型,获取所述第二类型的调用栈信息和所述错误信息,所述调用栈信息包括第一字符信息;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.一种基于Go语言的错误处理装置,其特征在于,所述装置包括:第一类型定义模块、第二类型第一模块、函数声明模块以及输出模块;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.根据权利要求3所述的装置,其特征在于,所述输出模块包括:获取单元,格式化单元以及输出单元;4. The device according to claim 3, characterized in that the output module comprises: 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.一种电子设备,包括:5. An electronic device, comprising:一个或多个处理器;one or more processors;存储装置,用于存储一个或多个程序,a storage device for storing one or more programs,其中,当所述一个或多个程序被所述一个或多个处理器执行时,使得所述一个或多个处理器执行根据权利要求1~2中任一项所述的方法。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.一种计算机可读存储介质,其上存储有可执行指令,该指令被处理器执行时使处理器执行根据权利要求1~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.一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现根据权利要求1~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.
CN202111575980.4A2021-12-212021-12-21 Error handling method, device, equipment, medium and product based on Go languageActiveCN114237624B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202111575980.4ACN114237624B (en)2021-12-212021-12-21 Error handling method, device, equipment, medium and product based on Go language

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202111575980.4ACN114237624B (en)2021-12-212021-12-21 Error handling method, device, equipment, medium and product based on Go language

Publications (2)

Publication NumberPublication Date
CN114237624A CN114237624A (en)2022-03-25
CN114237624Btrue CN114237624B (en)2024-12-20

Family

ID=80760931

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202111575980.4AActiveCN114237624B (en)2021-12-212021-12-21 Error handling method, device, equipment, medium and product based on Go language

Country Status (1)

CountryLink
CN (1)CN114237624B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN111813465A (en)*2020-06-192020-10-23北京字节跳动网络技术有限公司Information acquisition method, device, medium and equipment
CN112083976A (en)*2020-08-122020-12-15北京字节跳动网络技术有限公司Information acquisition method, device, medium and equipment

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US7685573B2 (en)*2003-07-312010-03-23Sun Microsystems, Inc.Flexible error trace mechanism
CN113342431B (en)*2021-06-292023-02-07苏州科达科技股份有限公司Function call stack backtracking and program exception handling method, device, equipment and medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN111813465A (en)*2020-06-192020-10-23北京字节跳动网络技术有限公司Information acquisition method, device, medium and equipment
CN112083976A (en)*2020-08-122020-12-15北京字节跳动网络技术有限公司Information acquisition method, device, medium and equipment

Also Published As

Publication numberPublication date
CN114237624A (en)2022-03-25

Similar Documents

PublicationPublication DateTitle
CN111221521B (en) Log code generation method, device, computer system and readable storage medium
CN109062563B (en)Method and device for generating page
CN113515271B (en)Service code generation method and device, electronic equipment and readable storage medium
WO2017089943A1 (en)Secure deployment of an application across deployment locations
CN110764748B (en)Code calling method, device, terminal and storage medium
CN110109983B (en)Method and device for operating Redis database
CN113761871B (en) Rich text rendering method, device, electronic device and storage medium
CN114254389B (en)Message desensitizing method, device, electronic equipment and medium
CN115982491A (en)Page updating method and device, electronic equipment and computer readable storage medium
CN113448578A (en)Page data processing method, processing system, electronic device and readable storage medium
CN114490136A (en) Service invocation and provisioning methods, apparatus, electronic equipment, media and program products
CN113656041A (en) Data processing method, apparatus, equipment and storage medium
CN116185384A (en)Visual development method, electronic equipment and storage medium
CN115130002A (en)Recommendation request processing method and device, computer equipment and storage medium
CN110888972A (en)Sensitive content identification method and device based on Spark Streaming
CN113760262B (en) Task processing method, device, computer system and computer readable storage medium
CN114237624B (en) Error handling method, device, equipment, medium and product based on Go language
CN113535565B (en)Interface use case generation method, device, equipment and medium
CN114677114A (en)Approval process generation method and device based on graph dragging
CN112068814B (en) Method, device, system and medium for generating executable file
CN115098530A (en) Data acquisition method and device
CN114371839A (en)Interface arrangement method and device based on graphic data
CN114138245A (en)Data processing method and device based on pipeline communication
CN113051090A (en)Interface processing method and device, interface calling method and device, system and medium
CN112799954B (en)Method, apparatus and computer readable medium for quickly constructing test environment

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp