fmt.Errorf() Function in Golang With Examples Last Updated : 05 May, 2020 Comments Improve Suggest changes Like Article Like Report In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Errorf() function in Go language allow us use formatting features to create descriptive error messages. Moreover, this function is defined under the fmt package. Here, you need to import the "fmt" package in order to use these functions. Syntax: func Errorf(format string, a ...interface{}) error Parameters: This function accepts two parameters which are illustrated below: string: This is your error message with placeholder values such as %s for a string and %d for an integer. a ...interface{}: This is either constant variable name used in the code or any inbuilt function. Return Value: It returns the string as a value that satisfies error. Example 1: C // Golang program to illustrate the usage of // fmt.Errorf() function // Including the main package package main // Importing fmt import ( "fmt" ) // Calling main func main() { // Declaring some constant variables const name, dept = "GeeksforGeeks", "CS" // Calling the Errorf() function with verb // %q which is used for a single-quoted character err := fmt.Errorf("%q is a %q Portal.", name, dept) // Printing the error message fmt.Println(err.Error()) } Output: "GeeksforGeeks" is a "CS" Portal. Example 2: C // Golang program to illustrate the usage of // fmt.Errorf() function // Including the main package package main // Importing fmt and time import ( "fmt" "time" ) // Calling main func main() { // Calling Errorf() function with verb $v which is used // for printing structs err := fmt.Errorf("error occurred at: %v", time.Now()) // Printing the error fmt.Println("An error happened:", err) } Output: An error happened: error occurred at: 2009-11-10 23:00:00 +0000 UTC m=+0.000000001 Comment More infoAdvertise with us Next Article fmt.Errorf() Function in Golang With Examples K Kanchan_Ray Follow Improve Article Tags : Go Language Golang-fmt Similar Reads errors.New() Function in Golang with Examples Errors package in Golang is used to implement the functions to manipulate the errors. errors.New()function returns an error that formats like given text. Each call to New returns distinct error value indeed in the event that the content is indistinguishable. Syntax: func New(text string) error It re 1 min read fmt.Scan() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Scan() function in Go language scans the input texts which is given in the standard input, reads from there and stores the successive space-separated values into successive arg 2 min read fmt.print() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.print() function in Go language formats using the default formats for its operands and writes to standard output. Here Spaces are added between operands when any string is not 2 min read fmt.Scanf() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Scanf() function in Go language scans the input texts which is given in the standard input, reads from there and stores the successive space-separated values into successive ar 2 min read fmt.Fscan() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Fscan() function in Go language scans the specified text, read from r, and then stores the successive space-separated values into successive arguments. Here newlines get counte 3 min read fmt.Sscan() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sscan() function in Go language scans the specified texts and store the successive space-separated texts into successive arguments. Moreover, this function is defined under the 2 min read fmt.Printf() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Printf() function in Go language formats according to a format specifier and writes to standard output. Moreover, this function is defined under the fmt package. Here, you need 3 min read fmt.Fprint() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Fprint() function in Go language formats using the default formats for its operands and writes to w. Here Spaces are added between operands when any string is not used as a par 3 min read fmt.Scanln() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Scanln() function in Go language scans the input texts which is given in the standard input, reads from there and stores the successive space-separated values into successive a 2 min read fmt.Sscanf() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sscanf() function in Go language scans the specified string and stores the successive space-separated values into successive arguments as determined by the format. Moreover, th 2 min read Like