TutorialPedia.org
Toggle Menu
Home
Online Go Compiler
Tutorials
JavaScript Tutorials
Golang Tutorials
Linux Command Line Tutorials
Blog
All Posts
Go Error Handling
Practice handling and propagating errors effectively in Go.
1. What is the standard type used to represent errors in Go?
error
Exception
ErrorType
panic
2. Which of the following are valid ways to return an error from a function in Go?
Returning an error value
Using panic()
Using fmt.Errorf()
Using throw
3. The 'error' type in Go is an interface that declares a single method: Error() string.
True
False
4. What function is commonly used to create formatted error messages in Go (include package)?
5. Which function is used to recover from a panic in Go?
recover()
catch()
handle()
resume()
6. Which of the following are considered best practices for error handling in Go?
Check errors immediately after function calls
Ignore errors by assigning to '_'
Wrap errors using %w to provide context
Use panic for expected business logic errors
7. Using panic() is recommended for handling expected runtime errors (e.g., invalid user input) in Go.
True
False
8. What keyword is used to initiate a panic in Go?
9. What is the most common pattern to check if an error occurred in Go?
if err != nil
try { ... } catch (err)
except err
on error goto handleErr
10. Which of the following are valid error values in Go?
nil
errors.New("operation failed")
fmt.Errorf("wrapped: %w", err)
true
Reset
Answered 0 of 0 — 0 correct