gpt4 book ai didi

go - 在 golang 中提前捕获错误

转载 作者:IT王子 更新时间:2023-10-29 01:38:24 27 4
gpt4 key购买 nike

我有以下代码,当缺少属性 debug 时,程序因难以理解的错误而崩溃。我想捕获此错误并提供更好的消息,但我尝试过的方法不起作用我想避免。

var jsonParsedApp *gabs.Container = nil    

debug := jsonParsedApp.Path("debug").Data()
//This is what I’ve tried
if debug == nil {
log.Println(“Property debug is missing “)
}

最佳答案

有一个Exists方法

if jsonParsedApp.Exists("debug") {
// you can safely read it here
}

引用资料:

关于go - 在 golang 中提前捕获错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47507450/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com