天天看點

dip:添加抛作為函數屬性與命名參數

來表示

不抛

.因為

不抛

作為預設更好,用在

子產品頂

時,如果有要

的函數,就需要這個

了.因為

異常

成本大,是以預設

不抛

才是最經濟的,即不需要

異常

的開銷.

屬性僅對

函數/閉包

有用.

void bar() throw;

struct S1 {
    nothrow void foo() { bar(); } //錯誤,不允許抛
}

struct S2 {
    void foo() { bar(); } // 可抛
}
           
void abc() throw throw;   // 錯誤
void bar() throw nothrow; // 錯誤

nothrow:
    foo() throw; // 好

throw:
    def() nothrow; // 好