13.9.cpp

来自「这是C++的一部分练习程序!对初学者有一定的帮助作用。」· C++ 代码 · 共 56 行

CPP
56
字号
#include <iostream.h>
#include <string.h>
void fun1(),fun2(),fun3();
class Except
{
  public:
	Except()
	{ 	}
    char *returnExpt()	
	{
		return "Except";
	}
};
class M
{
  public:
	M(char *s)
	{
		strcpy(mag,s);
		cout<<"Constructor."<<mag<<endl;
	}
	~M()
	{  cout<<"Destructor."<<mag<<endl;  }
  private:
	char mag[80];
};
void main()
{
	try
	{
		fun1();
	}
	catch(Except &e)
	{
		cout<<"The exception is caught."<<e.returnExpt()<<endl;
	}
}
void fun1()
{
	M m("fun1()");
	fun2();
}
void fun2()
{
	M m("fun2()");
	fun3();
}
void fun3()
{
	Except e;
	M m("fun3()");
	throw e;
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?