Skip to content

Instantly share code, notes, and snippets.

@ksakae1216
Created July 2, 2018 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksakae1216/ea0ca98a4d1ac0f2f19d12a739223707 to your computer and use it in GitHub Desktop.
Save ksakae1216/ea0ca98a4d1ac0f2f19d12a739223707 to your computer and use it in GitHub Desktop.
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