Created
July 2, 2018 12:33
-
-
Save ksakae1216/ea0ca98a4d1ac0f2f19d12a739223707 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package funcpkg | |
import ( | |
"fmt" | |
) | |
// PanicFunc panicのサンプルです | |
func PanicFunc() { | |
// deferはpanicが発生しても呼ばれます、ファイルやDBのクローズ処理を書くと良いでしょう | |
defer func() { | |
fmt.Println("後処理2") | |
}() | |
fmt.Println("PanicFunc 開始") | |
doPanicFunc() | |
fmt.Println("PanicFunc 終了") // ここは実行されない | |
} | |
func doPanicFunc() { | |
defer func() { | |
fmt.Println("後処理1") | |
}() | |
// 何かいろいろ処理してパニック発生する | |
panic("パニック発生") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment