Programming · Flashcard

How does Go handle errors without the use of exceptions?

  • AFunctions return an error value as a result, which the caller must explicitly check
  • BErrors are caught with try/catch blocks that wrap the code that might fail
  • CThe runtime silently logs errors to standard error and continues execution normally
  • DAll errors immediately terminate the program with a non-zero exit code and stack trace

Why this is the answer

Go functions conventionally return error as the last return value. The caller checks if err != nil — making error handling explicit and visible in the code flow.

Official docs
Study in Gnoseed →