2017-07-28 3 views
0

私はこのコードを使用しています。このメソッドは、成功した呼び出しの後で例外をスローしません。私が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です。

答えて

2

あなたの例はありません例外がスローされなかったことを証明してください。

キャッチブロック内のcoutメッセージは、既にwcoutを使用していて、同じデバイス(stdout)に文字幅を混在させると、未定義の動作であるため表示されません。

変更wcoutからcout、あなたは例外をスローされた参照してくださいよ、あなたはちょうどあなたが期待されるメッセージが表示されませんでした。

関連する問題