Does the error mechanism in go use error or painc??

the try {} catche () {} structure in other languages is usually added under the entry function, and then trhow Exception is directly added when an exception occurs in the implementation of business logic

.

so in go, there are two ways, one is:

func A(a string) (res string, err error) {
    defer func() {
        if err := recover(); err != nil {
            fmt.Println(err)
        }
    }()
    res = B(a)
    return res, err
}

func B(b string) (res string) {
    if b == "a" {
        return "hello " + b
    } else {
        panic("params need a")
    }
}

my question is:

  1. what is the usage scenario of these two methods?
  2. what are the consequences of abusing panic?
Jun.08,2021

it is recommended to read two articles and you will understand.
https://blog.golang.org/defer.
https://www.jianshu.com/p/aee.
Golang error handling is necessary to have a good understanding

Menu