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

📄 chapter8_1.cpp

📁 这个是VC实例教程第8章节的第一个实例的源代码
💻 CPP
字号:
#include <iostream.h>

class CExcept
{
public:
	CExcept(int ExCode)
	{
		m_ExCode = ExCode;
	}

	int GetCode()
	{
		return m_ExCode;
	}
private:
	int m_ExCode;
};

void main()
{
	char ch;

	try
	{
		cout << "at begining of try block" << '\n';
		cout << "throw 'char *' exception? (y/n):";
		cin >> ch;
		if(ch == 'y' || ch == 'Y')
			throw "error description";

		cout << "throw 'int  1' exception? (y/n):";
		cin >> ch;
		if(ch == 'y' || ch == 'Y')
			throw 1;

		cout << "throw 'int  2' exception? (y/n):";
		cin >> ch;
		if(ch == 'y' || ch == 'Y')
			throw 2;

		cout << "throw 'class CException' exception? (y/n):";
		cin >> ch;
		if(ch == 'y' || ch == 'Y')
			throw CExcept(5);

		cout << "throw 'double' exception? (y/n):";
		cin >> ch;
		if(ch == 'y' || ch == 'Y')
			throw 3.14159;
		cout << "at end of try block(no exception thrown" << '\n';
	}

	catch(char *ErrorMsg)
	{
		cout << "'char *' exception thrown; exception message: " << ErrorMsg << '\n';
	}

	catch(int ErrorCode)
	{
		cout << "'int' exception thrown; exception code: " << ErrorCode << '\n';
	}

	catch(CExcept Except)
	{
		cout << "'class CExcept' exception thrown; code: " << Except.GetCode() << '\n';
	}

	catch(...)
	{
		cout << "unknown type of exception thrown" << '\n';
	}

	cout << "after last catch block" << '\n';
}



⌨️ 快捷键说明

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