From 15970c8d6d42d0c076585bbccc16a407b8710bec Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 16 Oct 2012 11:27:20 +1100 Subject: [PATCH] spec: more clarification about deferred functions Proposed new text to make matters clearer. The existing text was unclear about the state of result parameters when panicking. R=golang-dev, iant CC=golang-dev https://golang.org/cl/6653047 --- doc/go_spec.html | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index e7e6c78de5..8248e8c696 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -4735,6 +4735,9 @@ are in scope within the literal, the deferred function may access and modify the result parameters before they are returned. If the deferred function has any return values, they are discarded when the function completes. +(See also the section on handling panics.) +

+

@@ -5069,10 +5072,13 @@ func recover() interface{}
 When a function F calls panic, normal
 execution of F stops immediately.  Any functions whose
 execution was deferred by the
-invocation of F are run in the usual way, and then
-F returns to its caller.  To the caller, F
+invocation of F are immediately run in the usual way,
+but with the current values of any result parameters, and then
+F returns to its caller without executing the rest of
+the function.  To the caller, F
 then behaves like a call to panic, terminating its own
-execution and running deferred functions.  This continues until all
+execution and running deferred functions in the same manner.
+This continues until all
 functions in the goroutine have ceased execution, in reverse order.
 At that point, the program is
 terminated and the error condition is reported, including the value of
-- 
2.48.1