【发布时间】:2018-01-04 19:08:16
【问题描述】:
我正在使用这段代码,我发现该方法在成功调用后不会引发异常。如果我使用 std::cout 一切都很好并且抛出异常。我正在使用 gcc 4.9.2 版(Debian 4.9.2-10)。是 gcc 错误还是 stl 错误代码问题或其他什么?
// exceptions
#include <iostream>
using namespace std;
class C {
public:
string srch(int &i) {
if (i == 0) { //found
wcout << "got it: " << i << endl; return "i";
}
throw std::exception();
}
};
int main () {
C c = C();
int i = 2;
int j = 0;
try
{
c.srch(j);
c.srch(i);
}
catch (const std::exception &e) {
cout << "An exception occurred. Exception Nr. " << e.what() << '\n';
}
return 0;
}
这是ideone link to reproduce the lack of an exception with wcout. 和a link reproducing the exception when cout is used。
【问题讨论】:
标签: c++ c++11 exception gcc std