W3Tutorials.net
Toggle Menu
Home
Online Go Compiler
Tutorials
Javascript Tutorials
Python Tutorials
Go Tutorials
Blog
All Posts
Go Error Handling
Review error handling practices and idioms in Go.
1. What is the primary interface type for errors in Go?
error
Error
Err
ErrorType
2. Which of the following functions typically return an error as their last return value? (Select all that apply)
os.Open
fmt.Println
json.Marshal
math.Sqrt
3. In Go, errors are treated as values rather than exceptions.
True
False
4. What function is commonly used to create a basic error message in Go? (full function name)
5. Which pattern is standard for checking if an error occurred in Go?
if err == nil
if err != nil
try { ... } catch (err)
if err.Error() == ""
6. Which are considered good error handling practices in Go? (Select all that apply)
Check errors before using the operation result
Wrap errors with context using fmt.Errorf
Use type assertions to handle specific error types
Ignore errors by assigning them to _
7. Panic should be used for recoverable errors in production code.
True
False
8. What verb in fmt.Errorf is used to wrap an error for later unwrapping with errors.Unwrap?
9. What does the Error() method of the error interface return?
An integer error code
A string description of the error
A boolean indicating success
A stack trace
10. Which are valid ways to define custom errors in Go? (Select all that apply)
A struct implementing the error interface
A string type with an Error() method
Embedding an error field in a struct for wrapping
A numeric type without methods
Reset
Answered 0 of 0 — 0 correct