Commit 15970c8d authored by Rob Pike's avatar Rob Pike

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
parent 6273c732
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of October 10, 2012",
"Subtitle": "Version of October 12, 2012",
"Path": "/ref/spec"
}-->
......@@ -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 <a href="#Handling_panics">handling panics</a>.)
</p>
</p>
<pre>
......@@ -5069,10 +5072,13 @@ func recover() interface{}
When a function <code>F</code> calls <code>panic</code>, normal
execution of <code>F</code> stops immediately. Any functions whose
execution was <a href="#Defer_statements">deferred</a> by the
invocation of <code>F</code> are run in the usual way, and then
<code>F</code> returns to its caller. To the caller, <code>F</code>
invocation of <code>F</code> are immediately run in the usual way,
but with the current values of any result parameters, and then
<code>F</code> returns to its caller without executing the rest of
the function. To the caller, <code>F</code>
then behaves like a call to <code>panic</code>, 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment