std::bad_alloc& e 相当于python的execpt Exption as e
#include <iostream> using namespace std; void abc(){ throw "adfadf"; } int main(int argc, char const *argv []){ try { abc(); }catch(bad_alloc& e){ printf("%s ", e.what()); } return 0; }
例子二
#include <iostream> using namespace std; int main(){ try{ throw "sdf"; }catch(int intError){ cout << intError <<' '; }catch(...){ cout << "未知错误" <<' '; } cout <<"hello world!!!" <<' '; return 0; }