ADVERTISEMENT
ADVERTISEMENT

Golang strconv.ErrSyntax Variable with Examples

Golang | strconv.ErrSyntax Variable: Here, we are going to learn about the ErrSyntax variable of the strconv package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 05, 2021

strconv.ErrSyntax Variable

The ErrSyntax variable is an inbuilt variable of the strconv package which indicates that a value does not have the right syntax for the target type. The value of the ErrSyntax variable is "invalid syntax".

Syntax:

*errors.errorString strconv.ErrSyntax
var ErrSyntax = errors.New("invalid syntax")

Parameter(s):

  • None

Return Value:

The return type of strconv.ErrSyntax variable is a *errors.errorString, it returns the string "invalid syntax".

Example 1:

// Golang program to demonstrate the
// example of strconv.ErrSyntax Variable

package main

import (
	"fmt"
	"strconv"
)

func main() {
	fmt.Printf("Type of strconv.ErrSyntax is %T\n", strconv.ErrSyntax)
	fmt.Println("Value of strconv.ErrSyntax:", strconv.ErrSyntax)
}

Output:

Type of strconv.ErrSyntax is *errors.errorString
Value of strconv.ErrSyntax: invalid syntax

Explanation:

In the above program, we imported the strconv package to use the strconv.ErrSyntax variable, then printed the type and value of the strconv.ErrSyntax variable.

Example 2:

// Golang program to demonstrate the
// example of strconv.ErrSyntax Variable

package main

import (
	"errors"
	"fmt"
	"os"
	"strconv"
)

func main() {
	b := "[email protected]"

	a, err := strconv.Atoi(b)

	if errors.Is(err, strconv.ErrSyntax) {
		fmt.Println("Error Detected:", strconv.ErrSyntax)
		os.Exit(1)
	}

	fmt.Println(a)
}

Output:

Error Detected: invalid syntax

Golang strconv Package »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.