Handle error exception and encoding problem