| // Copyright 2011 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. |
| // This file contains the code snippets included in "Defer, Panic, and Recover." |
| fmt.Println("Returned normally from f.") |
| if r := recover(); r != nil { |
| fmt.Println("Recovered in f", r) |
| fmt.Println("Calling g.") |
| fmt.Println("Returned normally from g.") |
| fmt.Println("Panicking!") |
| panic(fmt.Sprintf("%v", i)) |
| defer fmt.Println("Defer in g", i) |
| fmt.Println("Printing in g", i) |
| func CopyFile(dstName, srcName string) (written int64, err error) { |
| src, err := os.Open(srcName) |
| dst, err := os.Create(dstName) |