私はこのコードを使用しています。このメソッドは、成功した呼び出しの後で例外をスローしません。私がstd :: coutを使用すると、すべてが問題なく、例外がスローされます。私はgccバージョン4.9.2(Debian 4.9.2-10)を使用しています。それはgccバグかstlバグか、それとも他に何か?このコードの奇妙な動作(std :: wcoutとstd :: exception)
// 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です。