Posted on 2009-10-12 20:11
S.l.e!ep.¢% 閱讀(1410)
評(píng)論(2) 編輯 收藏 引用 所屬分類:
C++
#include?
<
iostream
>
using
?
namespace
?std;
void
?main()
{
????
try
????{????????
????????
try
????????{
????????????
//
?throw?int(10);???
//
?測(cè)試語(yǔ)句?1;
????????????
//
?throw;???????????
//
?測(cè)試語(yǔ)句?2;
????????}
????????
catch
(
int
?i)
????????{
????????????
throw
;
????????????std::cout?
<<
?i?
<<
?std::endl;
????????}
????}
????
catch
(
int
?i)
????{
????????std::cout?
<<
?
"
second?
"
?
<<
?i?
<<
?std::endl;?
????}
????
catch
(
)
????{
????????std::cout?
<<
?
"
unknown?exception
"
?
<<
?std::endl;
????}
????
//
throw;
}
(1) 當(dāng)采用 語(yǔ)句 1 時(shí),? second catch(int i) 可以捕獲到異常, 這說(shuō)明 throw; 有繼續(xù)拋異常的功效
(2) 當(dāng)采用 語(yǔ)句 2 時(shí), catch(...)捕獲不到異常,說(shuō)明,如果在沒(méi)異常而調(diào)用了 throw; 的情況下,異常的類型是無(wú)法預(yù)知的。。。。