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;
}

猜你喜欢

转载自www.cnblogs.com/renfanzi/p/9165877.html