?? 例14.2.txt
字號:
例14.2 在函數嵌套的情況下檢測異常處理。
這是一個簡單的例子,用來說明在try塊中有函數嵌套調用的情況下拋出異常和捕捉異常的情況。請自己先分析以下程序。
#include <iostream>
using namespace std;
int main( )
{void f1( );
try
{f1( );}//調用f1( )
catch(double)
{cout<<″OK0!″<<endl;}
cout<<″end0″<<endl;
return 0;
}
void f1( )
{void f2( );
try
{f2( );} //調用f2( )
catch(char)
{cout<<″OK1!″;}
cout<<″end1″<<endl;
}
void f2( )
{void f3( );
try
{f3( );} //調用f3( )
catch(int)
{cout<<″Ok2!″<<endl;}
cout<<″end2″<<endl;
}
void f3( )
{double a=0;
try
{throw a;} //拋出double類型異常信息
catch(float)
{cout<<″OK3!″<<endl;}
cout<<″end3″<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -