2010-03-13 64 views
1
SVector.H: 

    void pop_back() throw (underflow_error); 

在我的SVector.cpp文件中,我是否也應該包含throw(underflow_error)部分?我是否僅在函數頭或聲明中指定了異常類型? (C++)

void pop_back() throw (underflow_error) 
{ 
    // implementation 
} 

OR

void pop_back() 
{ 
    // implementation 
} 

感謝。

+0

就我個人而言,我討厭throw()語句。您可能對此感興趣:http://stackoverflow.com/questions/88573/should-i-use-an-exception-specifier-in-c – SoapBox 2010-03-13 01:41:38

+1

您可能對Herb Sutter撰寫的這篇文章感興趣(http:// www.gotw.ca/publications/mill22.htm):道德#1:永遠不要寫出異常規範。道德#2:除了可能是空的,但如果我是你,我甚至會避免。 – 2010-03-13 05:31:55

回答

8

15.4/2

如果函數的任何聲明有異常的規範,所有聲明,包括定義和明確的分工,該函數的應具有一個異常規範與同類型的集合-ids。