相关疑难解决方法(0)

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

当我的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;
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ stl exception

74
推荐指数
6
解决办法
15万
查看次数

标签 统计

c++ ×1

exception ×1

stl ×1