Improve error handling

Check the return value from iconv_open and raise the appropriate condition.