Go programs express error state with error
values.
The error
type is a built-in interface similar to fmt.Stringer
:
A nil error
denotes success; a non-nil error
denotes failure.
Functions often return an error
value, and calling code should handle errors by testing whether the error equals nil
.
Error Wrapping
recover
Go makes it possible to recover from a panic, by using the recover
built-in function. A recover
can stop a panic
from aborting the program and let it continue with execution instead.
Under the hood, recover
takes effect after panic
, so put it in defer
.