mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
complete string constant error example
parent
af4e0ae9a0
commit
53d589dd66
@ -49,6 +49,10 @@ If you want to create a constant string error, you can use a named type string:
|
||||
type errorConst string
|
||||
|
||||
const ErrTooManyErrors errorConst = "too many errors found."
|
||||
|
||||
type (e errorConst) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
```
|
||||
|
||||
Calling code would test for a special type of `error` by using a type switch:
|
||||
|
Loading…
x
Reference in New Issue
Block a user