c – 为什么要调用中止方法?

c – 为什么要调用中止方法?,第1张

概述在下面的程序中,即使我有适用的catch语句,也会调用abort方法.是什么原因? #include <iostream>#include <string>using namespace std;int main() { try { cout << "inside try\n"; throw "Text"; } catch (str 在下面的程序中,即使我有适用的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";}

当我运行程序时,我只在try里面显示第一个语句,然后我收到此错误:

为什么即使在我处理字符串异常时也会调用abort?

解决方法 真的很简单!

你扔了char const *,但没有匹配的catch.

你的意思是抛出std :: string(“…”);?

总结

以上是内存溢出为你收集整理的c – 为什么要调用中止方法?全部内容,希望文章能够帮你解决c – 为什么要调用中止方法?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1234935.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存