How to detect uncatched errors?

xuanbao · · 695 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>There is any tool to analyse the code and detect uncatched errors?</p> <hr/>**评论:**<br/><br/>usernameliteral: <pre><p><a href="https://github.com/kisielk/errcheck" rel="nofollow">https://github.com/kisielk/errcheck</a></p></pre>diegobernardes: <pre><p>thanks!</p></pre>R2A2: <pre><p>It&#39;s an awesome tool. I&#39;d love to use to verify builds, but we&#39;d have to alter our policy on using deferred calls (e.g. &#39;defer file.Close()&#39;) first.</p> <p>In most cases I&#39;d like to wrap them in a function which logs errors, but I think it&#39;s good to contain the use of <code>defer</code> to cases when you really don&#39;t need to know the outcome - e.g. &#39;close&#39; on a file read seems much less important than &#39;close&#39; while writing a file</p></pre>iqandjoke: <pre><p>I used that tool, but I&#39;m not sure if the below modification is good or not.</p> <p>Change <code>defer resp.Body.Close()</code> into</p> <pre><code>defer func() { if err := resp.Body.Close(); err != nil { log.Fatal(err) } }() </code></pre> <p>So which one is better?</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

695 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传