mirror of
https://github.com/golang/go
synced 2024-11-21 22:14:41 -07:00
doc/effective_go: add a note about prefixing error strings with their
package name. R=r, rsc CC=golang-dev https://golang.org/cl/4630042
This commit is contained in:
parent
278952c393
commit
ca91ce2d85
@ -233,9 +233,9 @@ Since the whole declaration is presented, such a comment can often be perfunctor
|
|||||||
<pre>
|
<pre>
|
||||||
// Error codes returned by failures to parse an expression.
|
// Error codes returned by failures to parse an expression.
|
||||||
var (
|
var (
|
||||||
ErrInternal = os.NewError("internal error")
|
ErrInternal = os.NewError("regexp: internal error")
|
||||||
ErrUnmatchedLpar = os.NewError("unmatched '('")
|
ErrUnmatchedLpar = os.NewError("regexp: unmatched '('")
|
||||||
ErrUnmatchedRpar = os.NewError("unmatched ')'")
|
ErrUnmatchedRpar = os.NewError("regexp: unmatched ')'")
|
||||||
...
|
...
|
||||||
)
|
)
|
||||||
</pre>
|
</pre>
|
||||||
@ -2673,6 +2673,13 @@ it is much more informative than the plain
|
|||||||
"no such file or directory".
|
"no such file or directory".
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
When feasible, error strings should identify their origin, such as by having
|
||||||
|
a prefix naming the package that generated the error. For example, in package
|
||||||
|
image, the string representation for a decoding error due to an unknown format
|
||||||
|
is "image: unknown format".
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Callers that care about the precise error details can
|
Callers that care about the precise error details can
|
||||||
use a type switch or a type assertion to look for specific
|
use a type switch or a type assertion to look for specific
|
||||||
|
Loading…
Reference in New Issue
Block a user