1
2
3
4
5
6
7 package main
8
9 import (
10 "runtime"
11 "strings"
12 )
13
14 func f() {
15 var x *string
16
17 for _, i := range *x {
18 println(i)
19 }
20 }
21
22 func g() {
23 }
24
25 func main() {
26 defer func() {
27 for i := 0;; i++ {
28 pc, file, line, ok := runtime.Caller(i)
29 if !ok {
30 print("BUG: bug348: cannot find caller\n")
31 return
32 }
33 if !strings.Contains(file, "bug348.go") || runtime.FuncForPC(pc).Name() != "main.f" {
34
35 continue
36 }
37 if line != 17 {
38 print("BUG: bug348: panic at ", file, ":", line, " in ", runtime.FuncForPC(pc).Name(), "\n")
39 return
40 }
41 recover()
42 return
43 }
44 }()
45 f()
46 }
47
View as plain text