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
+29.9k Golang : How to get HTTP request header information?
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+13.1k Golang : How to get a user home directory path?
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+5.1k Golang : Check if a word is countable or not
+36.7k Golang : Display float in 2 decimal points and rounding up or down
+37.5k Upload multiple files with Go
+7.7k Golang : Test if an input is an Armstrong number example
+11.6k Get form post value in Go
+87.8k Golang : How to convert character to ASCII and back
+23.9k Golang : Use regular expression to validate domain name