#include #include #include using std::cin, std::cout, std::string; class ArrayException { const char *info; public: ArrayException(const char *what) : info{what} { } void print() const { std::cout << info << '\n'; } }; class IntArray { int data[10]; public: int &operator[](int index) { if (index < 0 || index >= 10) throw ArrayException{"下标越界"}; return data[index]; } }; int main() { try { IntArray array{}; array[10] = 5; } catch (const ArrayException &exception) { exception.print(); } }