
Error Handling
Error type, error wrapping, errors.Is, errors.As, custom errors, panic/recover
1What is the interface used to represent errors in Go?
What is the interface used to represent errors in Go?
Cevap
The error interface is the predefined interface in Go to represent error conditions. It contains a single Error() method that returns a string describing the error. The nil value represents no error. This is the conventional interface used by all standard library packages and Go developers to signal and propagate errors.
2How to create a simple error with a static message in Go?
How to create a simple error with a static message in Go?
Cevap
The errors.New() function from the errors package creates a simple error with a static message. It returns an error type that implements the error interface with the provided message. This approach is recommended for creating sentinel errors (predefined errors like os.ErrNotExist) or simple errors without dynamic context. For dynamic messages, use fmt.Errorf().
3Which function allows creating an error with a dynamically formatted message?
Which function allows creating an error with a dynamically formatted message?
Cevap
The fmt.Errorf() function creates an error with a dynamically formatted message using format verbs (like %s, %d, %v). It also supports the special %w verb to wrap an existing error, preserving the error chain for later inspection. This is the recommended method for adding context to errors while keeping the original error.
Which format verb allows wrapping an error with fmt.Errorf()?
Which function checks if a wrapped error matches a specific error?
+17 mülakat soruları
Diğer Go mülakat konuları
Go Basics
Go Data Structures
Go Interfaces
Goroutines Basics
Channels
Go Modules
HTTP Server
HTTP Client
JSON Encoding
database/sql
Context Package
Testing
Concurrency Patterns
Sync Primitives
Go Web Frameworks
REST API Design
gRPC
Reflection
Memory Management
Performance Optimization
Generics
Go Design Patterns
Microservices
Security & Authentication
Docker & Containerization
Kubernetes Basics
Advanced Go
CLI Development
Bir sonraki mülakatın için Go'de uzmanlaş
Tüm sorulara, flashcards'a, teknik testlere, code review alıştırmalarına ve mülakat simülatörlerine eriş.
Ücretsiz başla