我可以在catch(...)块中获取异常对象的类型名称吗?

时间:2015-06-26 08:45:15

标签: c++ visual-c++

我可以在catch(...)块中获取异常对象的类型名称吗?

#define EXIT_THROUGH_EXCEPTION 1
#define EXIT_THROUGH_UNKNOWN_EXCEPTION 2

void error_info(ostream& stream, const string& msg, unsigned int line);

int main()
try{ 
  // Here is main code...
}
catch (exception& ex){ // Any exception based on the std::exception class
  error_info(cerr, ex.what(), __LINE__);
  return EXIT_THROUGH_EXCEPTION;
}
catch (...){ // other exception type  
  // TODO: what is instead of "???"?
  error_info(cerr, "Unknown exception: " + typeid("???").name,  __LINE__);
  return EXIT_THROUGH_UNKNOWN_EXCEPTION;
}

0 个答案:

没有答案