异常处理

#include <iostream>
#include <stdexcept>
#include <vector>
using namespace std;

class IsEmptyException : exception { };
class NotEnoughException : exception { };

void throwWhenNullOrEmpty(vector<intlist)
{
    if (list.size() == 0) {
        throw IsEmptyException();
    }
    if (list.size() < 10) {
        throw NotEnoughException();
    }
}

try {
    throwWhenNullOrEmpty({123});
}
catch (IsEmptyException & e) {
    cout << "list is empty";
}
catch (NotEnoughException & e) {
    cout << "not enough elements";
}