我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

上golang之前捕获错误

I have the following code and when the attribute debug is missing the program crashed with error which difficult to understand. I want to catch this error and provide better message but what I’ve tried is not working I want to avoid.

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 “)
}

There is an Exists method

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

References:

  • https://github.com/Jeffail/gabs/blob/master/gabs.go#L129

近期文章

  • 如何在Go中的测试中模拟HTTP请求的504超时错误?
  • 检查字符串是否为JSON格式
  • 正确从Golang输出JSON块
  • 轮班人数过多
  • Golang中的多模式JSON验证
  • 去包装不带大写字母导出功能
  • 如何将swagger ui与golang和goa集成
  • 使用Golang中的encoding / xml包制作soap xml
  • 使用Golang 1.10无法编译Windows DLL
  • 在Golang服务器中设置Cookie后,无法在Chrome检查应用程序Cookie中看到Cookie
  • 如何解组未知字段名称的JSON以构造[重复]
  • 在Golang中如何“匹配相同编号的组的内容”?
  • 如何在GO中解码灵活的xml?
  • 流执行命令StdoutPipe
  • 删除自己的二进制文件的可能性
  • 覆盖接口指针值
  • Aerospike Golang ListInsertOp多个值
  • Java中是否有类似于Go's Select的关键字或方法?
  • 通过SSL将Golang mgo连接到Mongo
  • mgo go服务器中打开文件过多

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华