Fix throwing std::bad_alloc if character set conversion fails.