Documents Packages The Project Help Blog The Go Programming Language Go Wins 2010 Bossie Award Share Memory By Communicating golang.org Install Go A Tour of Go Go Documentation Go Mailing List Go on Google+ Go+ Community Go on Twitter Blog index The Go Blog Defer, Panic, and Recover 4 August 2010 Go has the usual mechanisms for control flow: if, for, switch, goto. It also has the go statement to run code in a separate goroutine. Here I'd like to discuss some of the less common ones: defer, panic, and recover. A defer statement pushes a function call onto a list. The list of saved calls is executed after the surrounding function returns. Defer is commonly used to simplify functions that perform various clean-up actions. For example, let's look at a function that opens two files and copies the contents of one file to the other: func CopyFile(dstName, s...