Added the fmt.Errorf function, and how to create error constants

Nika Jones 2018-10-09 01:12:43 -07:00
parent 802ab6f283
commit a0668e2630

@ -10,6 +10,14 @@ if failure {
}
```
or by using `fmt.Errorf`:
```go
if failure {
return fmt.Errorf("inverse tachyon pulse failed")
}
```
Error strings should not start with a capital letter because they'll often be prefixed before printing:
```go
@ -35,6 +43,14 @@ func (p ParseError) Error() string {
}
```
If you want to create a constant string error, you can use a named type string:
```go
type errorConst string
const ErrTooManyErrors errorConst = "too many errors found."
```
Calling code would test for a special type of `error` by using a type switch:
```go