标签:size null cte pre protect highlight blog 异常处理 main
#include<iostream> using namespace std; class MyArray { public: MyArray(int m_len); ~MyArray(); public: class eSize { public: eSize(int len) { m_len11 = len; } virtual void printErr() { ; } protected: int m_len11; }; class eNegative :public eSize { public: eNegative(int len):eSize(len) { m_len11 = len; } virtual void printErr() { ; } }; class eZero:public eSize { public: eZero(int len):eSize(len) { m_len11 = len; } virtual void printErr() { ; } }; class eTooBig :public eSize { public: eTooBig(int len) :eSize(len) { m_len11 = len; } virtual void printErr() { ; } }; class eTooSmall :public eSize { public: eTooSmall(int len) :eSize(len) { m_len11 = len; } virtual void printErr() { ; } }; protected: private: int m_len; int *MySpace; }; MyArray::MyArray(int m_len) { this->m_len = m_len; if (m_len == 0) throw eZero(m_len); if (m_len <= 0) throw eNegative(m_len); if (m_len >= 1000) throw eTooBig(m_len); if (m_len <= 10) throw eTooSmall(m_len); } MyArray:: ~MyArray() { if (MySpace != NULL) { delete [] MySpace; MySpace = NULL; m_len = 0; } } int main() { try { MyArray a(-5); } catch (MyArray::eSize &e) { //cout << "len的大小: " << e.eSize(); e.printErr(); } catch (...) { } cout << "hello..." << endl; system("pause"); return 0; }
标签:size null cte pre protect highlight blog 异常处理 main
原文地址:http://www.cnblogs.com/xiaochige/p/6822312.html