<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Error on Debimate</title><link>https://debimate.jp/tags/error/</link><description>Recent content in Error on Debimate</description><image><title>Debimate</title><url>https://debimate.jp/images/default-ogp.jpg</url><link>https://debimate.jp/images/default-ogp.jpg</link></image><generator>Hugo -- 0.161.1</generator><language>ja-jp</language><lastBuildDate>Mon, 13 Dec 2021 00:00:00 +0000</lastBuildDate><atom:link href="https://debimate.jp/tags/error/index.xml" rel="self" type="application/rss+xml"/><item><title>【golang】errorsパッケージ New(), Unwrap(), Is(), As()の使い方と注意点</title><link>https://debimate.jp/post/ja/2021-12-13-golangerrors%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8-new-unwrap-is-as%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9%E3%81%A8%E6%B3%A8%E6%84%8F%E7%82%B9/</link><pubDate>Mon, 13 Dec 2021 00:00:00 +0000</pubDate><guid>https://debimate.jp/post/ja/2021-12-13-golangerrors%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8-new-unwrap-is-as%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9%E3%81%A8%E6%B3%A8%E6%84%8F%E7%82%B9/</guid><description>&lt;h3 id="前書き君err--nilしかできないの"&gt;前書き：君、err != nilしかできないの?&lt;/h3&gt;
&lt;p&gt;Golangでは、errorがnilでなければ上位関数にそのままerrorを戻す処理が頻繁にあります。&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;f, err := os.Create(path)
if err != nil {
return err
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;「エラーが発生した事実」を上位関数へ伝えるだけであれば、上記コードの対応で問題ありません。しかし、エラーの種類によって異なる対応をしたい場合は、nilチェックだけでは物足りません。&lt;/p&gt;</description></item></channel></rss>