Back to list

Go Error Handling 🐹

Lv.5387@mukitaro33 playsDec 30, 2025

The most famous phrase in Go history. You will type this line until you dream about it.

preview.go
Go
1package main
2
3import "errors"
4import "fmt"
5
6func main() {
7 if err := doTask1(); err != nil {
8 fmt.Println(err)
9 return
10 }
11 if err := doTask2(); err != nil {
12 fmt.Println(err)
13 return
14 }
15 if err := doTask3(); err != nil {
16 fmt.Println(err)
17 return
18 }
19 fmt.Println("Success!")
20}
21
22func doTask1() error { return nil }
23func doTask2() error { return nil }
24func doTask3() error { return errors.New("oops") }

Custom problems are not included in rankings