Golang encoding/hex.InvalidByteError.Error() function example
package encoding/hex
InvalidByteError values describe errors resulting from an invalid byte in a hex string.
Golang encoding/hex.InvalidByteError.Error() function usage example
package main
import (
"encoding/hex"
"fmt"
"os"
)
func main() {
str := "abcd你好" // <----- simulate some error
b, err := hex.DecodeString(str)
if err != nil {
fmt.Println(err.Error()) // <---- here
os.Exit(1)
}
fmt.Printf("Decoded bytes %v \n ", b)
}
Output :
encoding/hex: invalid byte: U+00E4 'ä'
exit status 1
Reference :
Advertisement
Something interesting
Tutorials
+18.2k Golang : Get command line arguments
+11.3k Golang : Intercept and process UNIX signals example
+19.2k Golang : Check whether a network interface is up on your machine
+55.3k Golang : Unmarshal JSON from http response
+28.6k Get file path of temporary file in Go
+9k Golang : Capture text return from exec function example
+35.1k Golang : Upload and download file to/from AWS S3
+4.9k Unix/Linux : secure copying between servers with SCP command examples
+7.6k Golang : Convert(cast) io.Reader type to string
+19.9k Golang : How to get time from unix nano example
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?