教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 golang 转换为字符串_在Golang中,如何将错误转换为字符串?

golang 转换为字符串_在Golang中,如何将错误转换为字符串?

发布时间:2023-02-27   编辑:jiaochengji.com
教程集为您提供golang 转换为字符串,在Golang中,如何将错误转换为字符串?等资源,欢迎您收藏本站,我们将为您提供最新的golang 转换为字符串,在Golang中,如何将错误转换为字符串?资源

golang 转换为字符串

In Golang, fmt.Println(err) can print out the error err. But how to convert an error to a string explicitely?

在Golang中, fmt.Println(err)可以打印出错误 err 。 但是如何将错误显式转换为字符串 ?

In Go, the error type has an interface

在Go中, error类型具有接口

type error interface {
    Error() string
}

Ref: https://golang.org/pkg/builtin/#error

参考: https : //golang.org/pkg/builtin/#error

So, for an error err, you can call

因此,对于错误err ,您可以致电

err.Error()

to get a string representing err.

得到一个表示err的字符串。

Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自: https://www.systutorials.com/in-golang-how-to-convert-an-error-to-a-string/

golang 转换为字符串

到此这篇关于“golang 转换为字符串_在Golang中,如何将错误转换为字符串?”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
Golang 标准库:strconv 包的应用
Go安装、变量声明、strings模块
php字符串函数有哪些
未结束的字符串常量怎么解决
js 未结束的字符串常量错误怎么解决
控讨:Javascript 强制类型转换
js字符串数组相互转换
php数字类型之字符串类型详解
Golang string
Python字符串详解

[关闭]
~ ~