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
+20.2k Golang : Compare floating-point numbers
+8.8k Golang : Get final balance from bit coin address example
+10.3k Golang : Convert file unix timestamp to UTC time example
+17k Golang : Covert map/slice/array to JSON or XML format
+12.7k Golang : Pass database connection to function called from another package and HTTP Handler
+13.3k Golang : Linear algebra and matrix calculation example
+10.1k Golang : Identifying Golang HTTP client request
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+44.9k Golang : Use wildcard patterns with filepath.Glob() example
+6.6k Golang : How to validate ISBN?
+12.8k Swift : Convert (cast) Int or int32 value to CGFloat