Karteikarten
Errors
Karten in diesem Stapel (15)
- 1What value does a Go function return to indicate an error?A Go function returns an `error` value as the last return value to indicate if an error occurred.
- 2What does a `nil` error value indicate?A `nil` error value indicates that no error occurred.
- 3How can you create a new error in Go?You can create a new error using `errors.New()` or `fmt.Errorf()`.
- 4How should you check for errors in Go, rather than using exceptions?You should check for errors using `if` statements, not exceptions.
- 5What are sentinel errors in Go?Sentinel errors indicate a specific error condition where no further processing is possible.
- 6Where are sentinel errors declared in Go?Sentinel errors are declared at the package level and should be treated as read-only.
- 7How do you test for sentinel errors in Go?You test for sentinel errors using the `==` operator.
- 8What is the nature of errors in Go?Errors in Go are interfaces, so you can define your own error types with additional information.
- 9How can you add context to errors in Go?You can add context to errors by "wrapping" them with `fmt.Errorf()` and `%w`.
- 10How can you unwrap errors in Go?You can unwrap errors using `errors.Unwrap()`.
- 11How can you wrap multiple errors in Go?You can wrap multiple errors using `errors.Join()`.
- 12How can you check if an error matches a specific sentinel error in Go?You can use `errors.Is()` to check if an error matches a specific sentinel error.
- 13How can you check if an error matches a specific custom error type in Go?You can use `errors.As()` to check if an error matches a specific custom error type.
- 14hat is the purpose of `panic()` in Go?panic()` is similar to exceptions, causing the program to exit.
- 15How can you handle panics in Go?You can use `defer` and `recover()` to handle panics.
Informationen
- Beschreibung
- Book Learning Go (CH9: Errors) Karteikarten am Errors, erstellt von Filipi Melo am 02/09/2024.
- Erstellt von
- Filipi Melo
- Aufrufe
- 0
- Bewertung