What is the strconv.ErrRange variable in Golang?

Overview

In Go, the ErrRange variable is a built-in variable of the strconv package, which indicates that a given value is out of range for the target type. It takes no parameters.

Syntax

*errors.errorString strconv.ErrRange
var ErrRange = errors.New("value out of range")

Return type

The return type of this variable is *errors.errorString.

Return value

This variable returns the "value out of range" string.

Example

package main
import (
"fmt"
"strconv"
)
func main() {
//Display the return type
fmt.Printf("The return type of strconv.ErrRange is %T\n", strconv.ErrRange)
// Display the return value
fmt.Println("the return value of strconv.ErrRange:", strconv.ErrRange)
}

Explanation

  • Line 1: We add the main package.

  • Lines 3–6: We import the other required packages.

  • Line 8: We define the main() function.

  • Line 10: We print the return type of the strconv.ErrSyntax variable.

  • Line 12: We print the return value of the strconv.ErrSyntax variable.

Free Resources