c++ - 如何获取 'catch(...)'中的异常信息

标签 c++ exception

<分区>

在C++中,我们可以通过catch(bad_cast& ex)获取异常信息,然后输出ex.what()的内容

try{
     //…
}catch(std::bad_alloc& e)
{
    cout << “Catch bad alloc exception ” << e.what() << endl;
}
catch(std::bad_cast& e)
{
    cout << “Catch bad alloc exception ” << e.what() << endl;
}
catch(std::bad_exception& e)
{
    cout << “Catch bad alloc exception ” << e.what() << endl;
}
// catch more exception types here
// … 
catch(...)
{
    // how to get the content of unknown exception?
}

如何从catch(...)获取异常信息?

最佳答案

这不是语言本身可以做的事情。

... 字面意思是“任何东西”。

你可以安全地对“任何东西”进行哪些操作? 在任何情况下,您都需要一种类型来检查。这更多地注意到了您已经做过的事情。

关于c++ - 如何获取 'catch(...)'中的异常信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25907079/

相关文章:

c++ - CreateFont() 创建的字体规范和大小不正确

jquery - 当未找到元素时,是否可以让 jQuery 抛出异常?

java - 如何正确抛出运行时异常并重启docker容器

c++ - boost::iostreams::mapped_file_sink 抛出未知异常

c++ - 如何在 C++ 中的字符串中查找元音?

c++ - int8_t 和 uint8_t 是 char 类型吗?

c++ - 我可以默认第一个模板参数吗?

c++ - vector 分配和内存使用

java - N 层系统中的异常

zend-framework - "Uncaught exception"不顾一切