-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75cf397
commit 828c501
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func c() (i int) { | ||
defer func() { i++ }() | ||
return 2 | ||
} | ||
|
||
func f() { | ||
deferfunc() { | ||
if r := recover(); r != nil { | ||
fmt.Println("Recovered in f", r) | ||
} | ||
}() | ||
fmt.Println("Calling g.") | ||
g(0) | ||
fmt.Println("Returned normally from g.") | ||
} | ||
|
||
func g(i int) { | ||
if i > 3 { | ||
fmt.Println("Panicking!") | ||
panic(fmt.Sprintf("%v", i)) | ||
} | ||
defer fmt.Println("Defer in g", i) | ||
fmt.Println("Printing in g", i) | ||
g(i + 1) | ||
} | ||
|
||
func main() { | ||
c := c() | ||
fmt.Println(c) | ||
|
||
f() | ||
fmt.Println("Returned normally from f.") | ||
} |