← BYTES
Go·Starter·Ref: 10.1.16
What is Go's built-in `error` type actually used for?
Have a question about this video? Mention reference 10.1.16 when you contact us.
a.It is an ordinary interface type (requiring an Error() string method) used as the conventional last return value of a function to signal failure
b.It is a special runtime construct only the compiler can produce
c.It immediately crashes the program the moment it is created
d.It can only be used for I/O-related failures, not other kinds of errors
error is just a built-in interface with one method, Error() string. By strong convention, a function that can fail returns its error as its final return value (e.g. (result Type, err error)), and the caller is expected to check if err != nil -- there is no exception-throwing mechanism in Go; this convention IS Go's primary error-handling idiom.
Find this on YouTube & Instagram
Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:
#BYTES#BYTES10116#Go