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
+8.8k Golang : Gorilla web tool kit schema example
+10.3k Golang : Embed secret text string into binary(executable) file
+22.1k Golang : Match strings by wildcard patterns with filepath.Match() function
+22.1k Golang : Join arrays or slices example
+17.2k Golang : Find file size(disk usage) with filepath.Walk
+8.5k Linux/Unix : fatal: the Postfix mail system is already running
+10.3k Golang : Wait and sync.WaitGroup example
+9.1k Golang : Gonum standard normal random numbers example
+17.6k Golang : Upload/Receive file progress indicator
+13.6k Golang : Set image canvas or background to transparent
+23.2k Golang : Print out struct values in string format
+9k Golang : Get SPF and DMARC from email headers to fight spam