c++ 的异常处理
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\n", e.what()); } return 0; }
例子二
#include <iostream> using namespace std; int main(){ try{ throw "sdf"; }catch(int intError){ cout << intError <<'\n'; }catch(...){ cout << "未知错误" <<'\n'; } cout <<"hello world!!!" <<'\n'; return 0; }
作者:沐禹辰
出处:http://www.cnblogs.com/renfanzi/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
出处:http://www.cnblogs.com/renfanzi/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。