因为 vector 得到 long unsigned int 调用f(-1)
throws bad_alloc
。我怀疑是用 2147483648 拨打电话,实际上是 18446744073709551615,因为它是 x64 系统。如何获取有关错误详细信息的信息?这可能是概括的,我怎样才能得到更多的细节e.what()
?
void f(int i){
vector<int> v(i);
printf("vector size: %d", v.size());
}
int main(int argc, char** argv) {
//f(1); // vector size: 1
try{
f(-1); // terminate called after throwing an instance of 'std::bad_alloc'
//what(): std::bad_alloc
}catch(std::bad_alloc& e){
printf("tried to allocate: %d bytes in vector constructor", e.?);
}
return 0;
}