ErrorKind
#enum ErrorKindThe general category of an error. Code decides on the kind; the message is for people.
| Name | Type | Description |
|---|---|---|
Other | | Any error that fits none of the other kinds. A throw "message" gets this kind. |
Syntax | | The input does not follow its format, such as a missing comma in JSON. |
UnexpectedEnd | | The input ended in the middle of a value. |
TypeMismatch | | A value has another type than the one asked for. |
MissingKey | | A required key or field is not there. |
OutOfRange | | A number, index or size is outside the allowed range. |
InvalidUtf8 | | Text is not valid UTF-8. |
InvalidArgument | | The caller passed a value the function cannot accept. |
NotFound | | What was asked for does not exist. |
AlreadyExists | | Something that should be new is already there. |
PermissionDenied | | The operation is not allowed. |
Io | | A read or write failed; trying again may work. |
Timeout | | Time ran out; trying again may work. |
Canceled | | The work was stopped on purpose. |
Unavailable | | A service is unavailable for now; trying again may work. |
Unsupported | | The input or the request uses something that is not supported. |
Internal | | A fault inside the program itself. |
func retryable(e: Error): bool:
ret e.Is(ErrorKind.Io) or e.Is(ErrorKind.Timeout) or e.Is(ErrorKind.Unavailable)
end
func main:
kinds := [
ErrorKind.Io, ErrorKind.Timeout, ErrorKind.Unavailable, ErrorKind.NotFound, ErrorKind.PermissionDenied,
ErrorKind.Internal
]
each kind in kinds:
e := Error.New(kind, "failed")
if retryable(e):
println e.KindName() + ": try again"
else:
println e.KindName() + ": give up"
end
end
endI/O error: try again timed out: try again unavailable: try again not found: give up permission denied: give up internal error: give up