1
2
3
4
5 package main
6
7 import (
8 "fmt"
9 "runtime"
10 )
11
12 func init() {
13 register("Crash", Crash)
14 register("DoublePanic", DoublePanic)
15 }
16
17 func test(name string) {
18 defer func() {
19 if x := recover(); x != nil {
20 fmt.Printf(" recovered")
21 }
22 fmt.Printf(" done\n")
23 }()
24 fmt.Printf("%s:", name)
25 var s *string
26 _ = *s
27 fmt.Print("SHOULD NOT BE HERE")
28 }
29
30 func testInNewThread(name string) {
31 c := make(chan bool)
32 go func() {
33 runtime.LockOSThread()
34 test(name)
35 c <- true
36 }()
37 <-c
38 }
39
40 func Crash() {
41 runtime.LockOSThread()
42 test("main")
43 testInNewThread("new-thread")
44 testInNewThread("second-new-thread")
45 test("main-again")
46 }
47
48 type P string
49
50 func (p P) String() string {
51
52
53 runtime.GC()
54 runtime.GC()
55 runtime.GC()
56 return string(p)
57 }
58
59
60
61 func DoublePanic() {
62 defer func() {
63 panic(P("YYY"))
64 }()
65 panic(P("XXX"))
66 }
67
View as plain text