Posted on 2009-10-12 20:11
S.l.e!ep.¢% 閱讀(1410)
評論(2) 編輯 收藏 引用 所屬分類:
C++
#include?
<
iostream
>
using
?
namespace
?std;
void
?main()
{
????
try
????{????????
????????
try
????????{
????????????
//
?throw?int(10);???
//
?測試語句?1;
????????????
//
?throw;???????????
//
?測試語句?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) 當采用 語句 1 時,? second catch(int i) 可以捕獲到異常, 這說明 throw; 有繼續(xù)拋異常的功效
(2) 當采用 語句 2 時, catch(...)捕獲不到異常,說明,如果在沒異常而調用了 throw; 的情況下,異常的類型是無法預知的。。。。