Raising error might be better, since this code would pass any encoding when invalid encoding name is provided.