首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >c++异常:抛出std::string

c++异常:抛出std::string
EN

Stack Overflow用户
提问于 2008-09-25 17:05:37
回答 3查看 171.5K关注 0票数 82

当我的C++方法遇到一些奇怪的东西并且不能恢复时,我想抛出一个异常。可以抛出一个std::string指针吗?

这是我期待做的事情:

void Foo::Bar() {
    if(!QueryPerformanceTimer(&m_baz)) {
        throw new std::string("it's the end of the world!");
    }
}

void Foo::Caller() {
    try {
        this->Bar(); // should throw
    }
    catch(std::string *caught) { // not quite sure the syntax is OK here...
        std::cout << "Got " << caught << std::endl;
    }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/134569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档