mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
35 lines
500 B
Go
35 lines
500 B
Go
|
|
// run
|
||
|
|
|
||
|
|
// Copyright 2025 The Go Authors. All rights reserved.
|
||
|
|
// Use of this source code is governed by a BSD-style
|
||
|
|
// license that can be found in the LICENSE file.
|
||
|
|
|
||
|
|
package main
|
||
|
|
|
||
|
|
func callRecover() {
|
||
|
|
func() {
|
||
|
|
if recover() != nil {
|
||
|
|
println("recovered")
|
||
|
|
}
|
||
|
|
}()
|
||
|
|
}
|
||
|
|
|
||
|
|
func F() int { callRecover(); return 0 }
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
mustPanic(func() {
|
||
|
|
defer F()
|
||
|
|
panic("XXX")
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
func mustPanic(f func()) {
|
||
|
|
defer func() {
|
||
|
|
r := recover()
|
||
|
|
if r == nil {
|
||
|
|
panic("didn't panic")
|
||
|
|
}
|
||
|
|
}()
|
||
|
|
f()
|
||
|
|
}
|