Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(835)

Delta Between Two Patch Sets: test/recover.go

Issue 871042: code review 871042: runtime: turn run time errors checks into panics (Closed)
Left Patch Set: code review 871042: runtime: turn run time errors checks into panics Created 14 years, 12 months ago
Right Patch Set: code review 871042: runtime: turn run time errors checks into panics Created 14 years, 12 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/golden.out ('k') | test/recover2.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // $G $D/$F.go && $L $F.$A && ./$A.out 1 // $G $D/$F.go && $L $F.$A && ./$A.out
2 2
3 // Copyright 2010 The Go Authors. All rights reserved. 3 // Copyright 2010 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style 4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file. 5 // license that can be found in the LICENSE file.
6 6
7 // Test of basic recover functionality. 7 // Test of basic recover functionality.
8 8
9 package main 9 package main
10 10
11 import "runtime" 11 import "runtime"
12 12
13 func main() { 13 func main() {
14 println("xxx")
14 test1() 15 test1()
16 println("xxx")
15 test1WithClosures() 17 test1WithClosures()
18 println("xxx")
16 test2() 19 test2()
20 println("xxx")
17 test3() 21 test3()
22 println("xxx")
18 test4() 23 test4()
24 println("xxx")
19 test5() 25 test5()
26 println("xxx")
20 test6() 27 test6()
28 println("xxx")
21 test6WithClosures() 29 test6WithClosures()
30 println("xxx")
22 test7() 31 test7()
23 } 32 }
24 33
25 func die() { 34 func die() {
26 runtime.Breakpoint() // can't depend on panic 35 runtime.Breakpoint() // can't depend on panic
27 } 36 }
28 37
29 func mustRecover(x interface{}) { 38 func mustRecover(x interface{}) {
30 mustNotRecover() // because it's not a defer call 39 mustNotRecover() // because it's not a defer call
31 v := recover() 40 v := recover()
(...skipping 10 matching lines...) Expand all
42 v = recover() 51 v = recover()
43 if v != nil { 52 if v != nil {
44 println("recover didn't recover") 53 println("recover didn't recover")
45 die() 54 die()
46 } 55 }
47 } 56 }
48 57
49 func mustNotRecover() { 58 func mustNotRecover() {
50 v := recover() 59 v := recover()
51 if v != nil { 60 if v != nil {
52 » » println("spurious recover") 61 » » println("spurious recover", v)
53 die() 62 die()
54 } 63 }
55 } 64 }
56 65
57 func withoutRecover() { 66 func withoutRecover() {
58 mustNotRecover() // because it's a sub-call 67 mustNotRecover() // because it's a sub-call
59 } 68 }
60 69
61 func test1() { 70 func test1() {
62 defer mustNotRecover() // because mustRecover will squelch it 71 defer mustNotRecover() // because mustRecover will squelch it
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // this test checks that the defer func on the next line actuall y runs. 246 // this test checks that the defer func on the next line actuall y runs.
238 defer func() { ok = true }() 247 defer func() { ok = true }()
239 defer mustRecover(7) 248 defer mustRecover(7)
240 panic(7) 249 panic(7)
241 }() 250 }()
242 if !ok { 251 if !ok {
243 println("did not run ok func") 252 println("did not run ok func")
244 die() 253 die()
245 } 254 }
246 } 255 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b