Short version there is nothing built into however you can implement it with a minimal learning curve using runtime.Caller
func HandleError(err error) (b bool) { if err != nil { // notice that we're using 1, so it will actually log where // the error happened, 0 = this function, we don't want that. _, fn, line, _ := runtime.Caller(1) log.Printf("[error] %s:%d %v", fn, line, err) b = true } return } //this logs the function name as well. func FancyHandleError(err error) (b bool) { if err != nil { // notice that we're using 1, so it will actually log the where // the error happened, 0 = this function, we don't want that. pc, fn, line, _ := runtime.Caller(1) log.Printf("[error] in %s[%s:%d] %v", runtime.FuncForPC(pc).Name(), fn, line, err) b = true } return } func main() { if FancyHandleError(fmt.Errorf("it the end of the world")) { log.Print("stuff") } }
playground
OneOfOne Jul 17 '14 at 17:11 2014-07-17 17:11
source share