change error_handler function signature to /3 from /6
extend error_handler to encoding
trap and process string encoding errors properly