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
+15.2k Golang : Get timezone offset from date or timestamp
+7.9k Golang Hello World Example
+7.5k Golang : Create zip/ePub file without compression(use Store algorithm)
+19.2k Golang : Check whether a network interface is up on your machine
+9.1k Golang : Get curl -I or head data from URL example
+14k Golang : Google Drive API upload and rename example
+5.7k Golang : Struct field tags and what is their purpose?
+8.3k Golang : Oanda bot with Telegram and RSI example
+4.8k PHP : Extract part of a string starting from the middle
+13.6k Golang : Set image canvas or background to transparent
+30.8k Golang : Download file example
+6.2k Golang : Extract XML attribute data with attr field tag example