error handling on encoding