github.com/goplus/gossa@v0.3.25/testdata/recover.go (about)

     1  package main
     2  
     3  // Tests of panic/recover.
     4  
     5  import "fmt"
     6  
     7  func fortyTwo() (r int) {
     8  	r = 42
     9  	// The next two statements simulate a 'return' statement.
    10  	defer func() { recover() }()
    11  	panic(nil)
    12  }
    13  
    14  func zero() int {
    15  	defer func() { recover() }()
    16  	panic(1)
    17  }
    18  
    19  func zeroEmpty() (int, string) {
    20  	defer func() { recover() }()
    21  	panic(1)
    22  }
    23  
    24  func main() {
    25  	if r := fortyTwo(); r != 42 {
    26  		panic(r)
    27  	}
    28  	if r := zero(); r != 0 {
    29  		panic(r)
    30  	}
    31  	if r, s := zeroEmpty(); r != 0 || s != "" {
    32  		panic(fmt.Sprint(r, s))
    33  	}
    34  }