unsigned idx = 0;
//about 30 lines of code for writing to standard output
//save std::cin's current exception mask because this code is part of a library
const std::ios_base::iostate cin_orig_mask(std::cin.exceptions());
//throw an exception if std::cin's badbit is set, since it signifies an irrecoverable stream error
std::cin.exceptions(std::ios_base::badbit);
while(true){
    std::cout << "Enter the number corresponding to your choice: ";
    try{
        std::cin >> idx;
    } catch(...){
        //restore the original exception mask
        std::cin.exceptions(cin_orig_mask);
        //unset badbit
        std::cin.clear();
        throw;
    }
    //check if failbit was set
    if(std::cin.fail()){
        std::cerr << "Invalid input\n";
        //discard the contents of the input buffer
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        std::cin.clear();
    } else if(idx <= dataset_list.GetArray().Size()){
        break;
    } else{
        std::cerr << idx << " does not correspond to any of the datasets listed\n";
    }
}