Skip to content

Commit a758acb

Browse files
committed
Add diff_logfatal_and_logpanic
1 parent de231f4 commit a758acb

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '3'
2+
3+
tasks:
4+
default:
5+
cmds:
6+
- task: run-logfatal
7+
- task: run-logpanic
8+
run-logfatal:
9+
cmds:
10+
- cmd: go run fatal/logfatal.go
11+
ignore_error: true
12+
run-logpanic:
13+
cmds:
14+
- cmd: go run panic/logpanic.go
15+
ignore_error: true
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
)
8+
9+
var (
10+
l = log.New(os.Stderr, ">>> ", 0)
11+
)
12+
13+
func main() {
14+
// log.Fatal は、os.Exit(1) を呼び出すのでdeferが呼ばれない
15+
// log.Fatal は、OSに戻り値 1 を返す (linuxの場合)
16+
//
17+
// REFERENCES:
18+
// - https://zenn.dev/spiegel/books/error-handling-in-golang/viewer/panics
19+
defer fmt.Println("call defer")
20+
l.Fatalln("call log.Fatal")
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
)
8+
9+
var (
10+
l = log.New(os.Stderr, ">>> ", 0)
11+
)
12+
13+
func main() {
14+
// log.Panic は、panicを呼び出すのでdeferが呼ばれる
15+
// log.Panic は、OSに戻り値 2 を返す (linuxの場合)
16+
//
17+
// REFERENCES:
18+
// - https://zenn.dev/spiegel/books/error-handling-in-golang/viewer/panics
19+
defer fmt.Println("call defer")
20+
l.Panicln("call log.Panic")
21+
}

0 commit comments

Comments
 (0)