3
// Copyright 2011 The Go Authors. All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
7
// This file contains the code snippets included in "Defer, Panic, and Recover."
17
fmt.Println("Returned normally from f.")
22
if r := recover(); r != nil {
23
fmt.Println("Recovered in f", r)
26
fmt.Println("Calling g.")
28
fmt.Println("Returned normally from g.")
33
fmt.Println("Panicking!")
34
panic(fmt.Sprintf("%v", i))
36
defer fmt.Println("Defer in g", i)
37
fmt.Println("Printing in g", i)
44
func CopyFile(dstName, srcName string) (written int64, err error) {
45
src, err := os.Open(srcName)
51
dst, err := os.Create(dstName)
57
return io.Copy(dst, src)