From 76cf6bac07a8188d99788d76a12774d0f9f5e3ec Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Fri, 23 Mar 2012 17:40:27 +1100 Subject: [PATCH] doc/articles/defer_panic_recover.html: minor tweaks Delete () from function names and change the reference to some functions to the correct term, methods. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/5874063 --- doc/articles/defer_panic_recover.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/articles/defer_panic_recover.html b/doc/articles/defer_panic_recover.html index 206b836d8a..c964cd368c 100644 --- a/doc/articles/defer_panic_recover.html +++ b/doc/articles/defer_panic_recover.html @@ -25,7 +25,7 @@ contents of one file to the other:

This works, but there is a bug. If the call to os.Create fails, the function will return without closing the source file. This can be easily -remedied by putting a call to src.Close() before the second return statement, +remedied by putting a call to src.Close before the second return statement, but if the function were more complex the problem might not be so easily noticed and resolved. By introducing defer statements we can ensure that the files are always closed: @@ -160,7 +160,8 @@ For a real-world example of panic and recover, see the It decodes JSON-encoded data with a set of recursive functions. When malformed JSON is encountered, the parser calls panic to unwind the stack to the top-level function call, which recovers from the panic and returns -an appropriate error value (see the 'error' and 'unmarshal' functions in +an appropriate error value (see the 'error' and 'unmarshal' methods of +the decodeState type in decode.go).

@@ -170,7 +171,7 @@ internally, its external API still presents explicit error return values.

-Other uses of defer (beyond the file.Close() example given earlier) +Other uses of defer (beyond the file.Close example given earlier) include releasing a mutex: