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
+10.8k Golang : Natural string sorting example
+12.8k Golang : http.Get example
+11.8k Golang : convert(cast) float to string
+5.3k PHP : Hide PHP version information from curl
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+6.9k Default cipher that OpenSSL used to encrypt a PEM file
+12.5k Golang : Forwarding a local port to a remote server example
+13.8k Golang : Gin framework accept query string by post request example
+21.6k Golang : GORM create record or insert new record into database example
+10.3k Golang : Convert file content to Hex
+10k Golang : Setting variable value with ldflags
+6.1k Golang : Debug with Godebug