add english version

This commit is contained in:
astaxie
2014-05-10 18:05:31 +08:00
parent 946300f0b1
commit eb5220f7eb
269 changed files with 16101 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
// Example code for Chapter 2.3 from "Build Web Application with Golang"
// Purpose: Showing how to use `panic()` and `recover()`
package main
import (
"fmt"
"os"
)
var user = os.Getenv("USER")
func check_user() {
if user == "" {
panic("no value for $USER")
}
fmt.Println("Environment Variable `USER` =", user)
}
func throwsPanic(f func()) (b bool) {
defer func() {
if x := recover(); x != nil {
fmt.Println("Panic message =", x);
b = true
}
}()
f() // if f causes panic, it will recover
return
}
func main(){
didPanic := throwsPanic(check_user)
fmt.Println("didPanic =", didPanic)
}