????21?????????????????????У?exception??new??type_info??stdexcept??

????22??exception?ж?????exception??new?ж?????bad_alloc??type_info?ж?????bad_cast??stdexcept?ж?????runtime_error??logic_error??

????23??runtime_error????????????????????????????overflow_error??underflow_error??range_error????????logic_error???????????????????domain_error??invalid_argument??out_of_range??length_error?????????????е???Щ????exception???????

????24??exception??bad_alloc??bad_cast?????????????????????????????Щ??????????????????????????????????????????????????????????????????????????????????????????????

????25???????????????what?麯????????????????C?????????????

????26????ó???????exception?????м???????????????????????exception???Ρ?

????27???????????????βα??????????????????throw??????????????????????????????磺void foo(int) throw(bad_alloc, invalid_argument);?????б??????????void foo(int) throw();??????ú?????????κ?????

????28???????????????????????????????????????????????????????????????κ???????????????????????????????????????????????????????д?ú????????????????????????????????б???????????????????

????29??????????е???????????what?麯??????????????????what?????????????virtual const char* what() const throw();??

????30?????????е??麯??????????????麯??????????????????????????д??????????????????????????????е????б????麯??????????汾????????????б???????

????31?????????????????????????????????????????????????????????????????????????????????????????????????????????????????new????????????棬????????????????????????????????????????佫??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Щ???????????????

void f() {
        const int N=10;
        int* p=new int[N];
        if(...) {
                throw exception;
        }
        delete[] p;
}

??????????????????p????????佫????????????????????????????????????????

template
class Resource {
private:
        unsigned int size;
        T* data;
public:
        Resource(unsigned int _size=0):size(_size),data(new T[_size]) {
                for(unsigned int i=0; i                         data[i]=T();
                }
        }
        Resource(const Resource& r):size(r.size),data(new T[r.size]) {
                for(unsigned int i=0; i                         data[i]=r.data[i];
                }
        }
        Resource& operator=(const Resource& r) {
                if(&r!=this) {

                        size=r.size;
                        delete[] data;
                        data=new T[size];
                        for(unsigned int i=0; i                                 data[i]=r.data[i];
                        }
                }
                return *this;
        }
        ~Resource() {delete[] data;}
        T operator[](unsigned int index);
        const T operator[](unsigned int index) const;
};
void f() {
        const int N=10;
        Resource p(N);
        if(...) {
                throw exception;
        }

}

???????T???????????????????????p????????????

????32???????????????????????????????????????????????е?????????????????????????????????????????????????????????????????????????????????????????????????????“??????伴?????”,????RAII????11??????????????÷???