Clarify the panic example with a comment about unreachable code

Fixes #390
This commit is contained in:
Eli Bendersky 2021-09-02 05:42:07 -07:00
parent 91c8ceec2c
commit 2acace92c0
2 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,11 @@
# Running this program will cause it to panic, print
# an error message and goroutine traces, and exit with
# a non-zero status.
# When first panic in `main` fires, the program exits
# without reaching the rest of the code. If you'd like
# to see the program try to create a temp file, comment
# the first panic out.
$ go run panic.go
panic: a problem

16
public/panic generated
View File

@ -117,6 +117,20 @@ returns an error value that we don’t know how to
an error message and goroutine traces, and exit with
a non-zero status.</p>
</td>
<td class="code empty leading">
</td>
</tr>
<tr>
<td class="docs">
<p>When first panic in <code>main</code> fires, the program exits
without reaching the rest of the code. If you&rsquo;d like
to see the program try to create a temp file, comment
the first panic out.</p>
</td>
<td class="code leading">
@ -166,7 +180,7 @@ to use error-indicating return values wherever possible.</p>
</div>
<script>
var codeLines = [];
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import \"os\"\u000A');codeLines.push('func main() {\u000A');codeLines.push(' panic(\"a problem\")\u000A');codeLines.push(' _, err :\u003D os.Create(\"/tmp/file\")\u000A if err !\u003D nil {\u000A panic(err)\u000A }\u000A}\u000A');codeLines.push('');codeLines.push('');codeLines.push('');
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import \"os\"\u000A');codeLines.push('func main() {\u000A');codeLines.push(' panic(\"a problem\")\u000A');codeLines.push(' _, err :\u003D os.Create(\"/tmp/file\")\u000A if err !\u003D nil {\u000A panic(err)\u000A }\u000A}\u000A');codeLines.push('');codeLines.push('');codeLines.push('');codeLines.push('');
</script>
<script src="site.js" async></script>
</body>