Erro Handling

About

In Go, error handling works a bit differently. You should write your functions in a way that errors should not crash the application.

func convert() (float64, error) {
    if a == '' {
        return nil, errors.New("It failed")
    }
    return 10, nil
}

Exit with panic

You can exit the program ungracefully with panic().

a, err = convert()
if err != nil {
    panic(err)
}

Last updated