August 2021
Beginner
112 pages
1h 23m
English
| Puzzle 19 | To Err or Not to Err |
| | package main |
| | |
| | import ( |
| | "fmt" |
| | ) |
| | |
| | type OSError int |
| | |
| | func (e *OSError) Error() string { |
| | return fmt.Sprintf("error #%d", *e) |
| | } |
| | |
| | func FileExists(path string) (bool, error) { |
| | var err *OSError |
| | return false, err // TODO |
| | } |
| | |
| | func main() { |
| | if _, err := FileExists("/no/such/file"); err != nil { |
| | fmt.Printf("error: %s\n", err) |
| | } else { |
| | fmt.Println("OK") |
| | } |
| | } |
Guess the Output | |
|---|---|
|
|
Try to guess what the output is before moving to the next page. |
Read now
Unlock full access