gpt4 book ai didi

c++ - 为什么调用 abort 方法?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:07:39 26 4
gpt4 key购买 nike

在下面的程序中,即使我已获得适用的 catch 语句,也会调用 abort 方法。这是什么原因?

#include <iostream>
#include <string>
using namespace std;

int main() {

try {
cout << "inside try\n";
throw "Text";
}
catch (string x) {
cout << "in catch" << x << endl;
}

cout << "Done with try-catch\n";
}

当我运行程序时,我只得到第一个语句 inside try 显示,然后我得到这个错误:

enter image description here

为什么即使我正在处理 string 异常也会调用 abort

最佳答案

真的很简单!

您抛出了 char const*,但没有匹配的 catch

你是说 throw std::string("..."); 吗?

关于c++ - 为什么调用 abort 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6548548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com