簡體   English   中英

我調用std :: abort()時未顯示cout

[英]cout not shown when I call std::abort()

當我在Windows 10的Visual Studio 2015中運行此代碼時,看不到輸出

That was unexpected

它適用於Linux上的gcc 5.3。

class X {};
class Y {};
class Z : public X {};
class W {};

void f() throw(X, Y)    // list what exceptions can be thrown
{
    int n = 0;
    if (n) throw X(); // OK
    if (n) throw Z(); // also OK
    throw W(); // will call std::unexpected()
}

int main() {
    std::set_unexpected([] {
        std::cout << "That was unexpected" << std::endl;
        std::abort();
    });
    f();
}

盡管接受了語法 ,但Visual C ++從未實現異常規范。

無論如何,它們在C ++ 11和更高版本中已被棄用。

可能是由於主要Windows C ++編譯器不符合所致。


同樣,我記得Visual C ++從未實現過std::uncaught_exception ,但是對此我不太確定。 值得在使用和依賴之前進行檢查。 …經過文檔檢查 :Visual C ++ 2015 文檔指出

在設備上,僅Windows CE 5.00和更高版本(包括Windows Mobile 2005平台)支持uncaught_exception

因此,在桌面平台上顯然受到支持。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM