Add error management in case of Encoding/Decoding failure

Now, user can now if there is any error when encoding/decoding
functions. These changes make simpler to manage error case.