c++11 - strange behaviour of this c++ piece of code (std::wcout and std::exception) -
this question has answer here:
- mixing cout , wcout in same program 5 answers
i'm working piece of code , i've found method doesn't throw exception after succesfull call. if use std::cout fine , exception thrown. i'm using gcc version 4.9.2 (debian 4.9.2-10). gcc bug or stl bug code problem or else?
// exceptions #include <iostream> using namespace std; class c { public: string srch(int &i) { if (i == 0) { //found wcout << "got it: " << << endl; return "i"; } throw std::exception(); } }; int main () { c c = c(); int = 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; } here's ideone link reproduce lack of exception wcout. , a link reproducing exception when cout used.
your example does not prove exception wasn't thrown.
the cout message in catch block not displayed, because used wcout , mixing character widths on same device (stdout) undefined behaviour.
change cout wcout , you'll see exception was thrown, didn't see message expected.
Comments
Post a Comment