mirror of
https://github.com/golang/go
synced 2024-11-25 06:07:58 -07:00
spec: add error
R=golang-dev, dsymonds, r, r CC=golang-dev https://golang.org/cl/5308072
This commit is contained in:
parent
9a0563548b
commit
d9877e22fe
@ -1,5 +1,5 @@
|
|||||||
<!-- title The Go Programming Language Specification -->
|
<!-- title The Go Programming Language Specification -->
|
||||||
<!-- subtitle Version of October 25, 2011 -->
|
<!-- subtitle Version of November 1, 2011 -->
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
TODO
|
TODO
|
||||||
@ -1498,12 +1498,10 @@ the body of any nested function.
|
|||||||
The following identifiers are implicitly declared in the universe block:
|
The following identifiers are implicitly declared in the universe block:
|
||||||
</p>
|
</p>
|
||||||
<pre class="grammar">
|
<pre class="grammar">
|
||||||
Basic types:
|
Types:
|
||||||
bool byte complex64 complex128 float32 float64
|
bool byte complex64 complex128 error float32 float64
|
||||||
int8 int16 int32 int64 rune string uint8 uint16 uint32 uint64
|
int int8 int16 int32 int64 rune string
|
||||||
|
uint uint8 uint16 uint32 uint64 uintptr
|
||||||
Architecture-specific convenience types:
|
|
||||||
int uint uintptr
|
|
||||||
|
|
||||||
Constants:
|
Constants:
|
||||||
true false iota
|
true false iota
|
||||||
@ -4323,7 +4321,7 @@ func complex_f3() (re float64, im float64) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (devnull) Write(p []byte) (n int, _ os.Error) {
|
func (devnull) Write(p []byte) (n int, _ error) {
|
||||||
n = len(p)
|
n = len(p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -5172,6 +5170,28 @@ the <code>init</code> functions: it will not start the next
|
|||||||
the previous one has returned.
|
the previous one has returned.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<h2 id="Errors">Errors</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The predeclared type <code>error</code> is defined as
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
type error interface {
|
||||||
|
Error() string
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
It is the conventional interface for representing an error condition,
|
||||||
|
with the nil value representing no error.
|
||||||
|
For instance, a function to read data from a file might be defined:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
func Read(f *File, b []byte) (n int, err error)
|
||||||
|
</pre>
|
||||||
|
|
||||||
<h2 id="Run_time_panics">Run-time panics</h2>
|
<h2 id="Run_time_panics">Run-time panics</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -5179,18 +5199,18 @@ Execution errors such as attempting to index an array out
|
|||||||
of bounds trigger a <i>run-time panic</i> equivalent to a call of
|
of bounds trigger a <i>run-time panic</i> equivalent to a call of
|
||||||
the built-in function <a href="#Handling_panics"><code>panic</code></a>
|
the built-in function <a href="#Handling_panics"><code>panic</code></a>
|
||||||
with a value of the implementation-defined interface type <code>runtime.Error</code>.
|
with a value of the implementation-defined interface type <code>runtime.Error</code>.
|
||||||
That type defines at least the method
|
That type satisfies the predeclared interface type
|
||||||
<code>String() string</code>. The exact error values that
|
<a href="#Errors"><code>error</code></a>.
|
||||||
represent distinct run-time error conditions are unspecified,
|
The exact error values that
|
||||||
at least for now.
|
represent distinct run-time error conditions are unspecified.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
type Error interface {
|
type Error interface {
|
||||||
String() string
|
error
|
||||||
// and perhaps others
|
// and perhaps other methods
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user