cpp:使用省略号捕获异常并查看信息 [英] cpp: catch exception with ellipsis and see the information

查看:129
本文介绍了cpp:使用省略号捕获异常并查看信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以捕获所有例外并通过

I know that you can catch "all exceptions" and print the exception by

try
{
    //some code...
}catch(const std::exception& e) {
   cout << e.what();
}

但这只是针对从std :: exception派生的异常。
我想知道是否有办法从省略号中获取一些信息

but this is just for exceptions derived from std::exception. I was wondering if there is a way to get some information from an ellipsis catch

try
{
    //some code...
}catch(...) {
   // ??
}

如果该机制与功能的省略号相同,那么我应该能够做类似强制转换 va_list 的参数并尝试调用 what()方法的操作。

If the mechanism is the same as ellipsis for functions then I should be able to do something like casting the argument of the va_list and trying to call the what() method.

我还没有尝试过,但是如果有人知道我会很兴奋的方式。

I haven't tried it yet but if someone knows the way I'd be excited to know how.

推荐答案

对不起,您不能这样做。您只能在 catch 块中访问特定异常类型的异常对象。

Sorry, you can't do that. You can only access the exception object in a catch block for a specific exception type.

这篇关于cpp:使用省略号捕获异常并查看信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆