publish panic and defer

This commit is contained in:
Mark McGranaghan
2012-10-22 17:37:29 -04:00
parent c98e6b6504
commit e721314b97
5 changed files with 77 additions and 23 deletions

View File

@@ -1,7 +1,16 @@
$ go run 26-panic.go
panic: O noes
# Running the program will cause it to panic, print
# an error message and goroutine traces, and exit with
# a non-zero status.
$ go run panic.go
panic: a problem
goroutine 1 [running]:
main.main()
/.../src/26-panic.go:4 +0x47
/.../panic.go:12 +0x47
...
exit status 2
# Note that unlike some languages which use exceptions
# for handling of many errors, in Go it is idiomatic
# to use error-indicating return values wherever possible.
# We'll learn more about this in later examples.