C++????????
???????????? ???????[ 2012/11/1 10:44:49 ] ????????
????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
}
}
Resource(const Resource& r):size(r.size),data(new T[r.size]) {
for(unsigned int i=0; i
}
}
Resource& operator=(const Resource& r) {
if(&r!=this) {
size=r.size;
delete[] data;
data=new T[size];
for(unsigned int i=0; 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
if(...) {
throw exception;
}
}
???????T???????????????????????p????????????
????32???????????????????????????????????????????????е?????????????????????????????????????????????????????????????????????????????????????????????????????“??????伴?????”,????RAII????11??????????????÷???
??????

???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11