⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 例14.2.txt

📁 是关于谭浩强老师的C++程序设计课程的程序源代码以及课件
💻 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 + -