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

📄 d_12_2.cpp

📁 C++应用教程原码,里面包含该书中有十三章内容的代码,详细具体
💻 CPP
字号:
#include "stdafx.h"
#include <iostream>
#include <string>
#include<iomanip>
using namespace std;

void function(void);
class overflow
{
public:
	overflow(){}
	~overflow(){}
	const char* ShowReason() const
	{
		return "这是overflow类异常,现在进行处理......";
	}
};
class A
{
public:
	A();
	~A();
};
A::A()
{
	cout<<"构造类A。"<<endl;
}
A::~A()
{
	cout<<"析构类A。"<<endl;
}
void function()
{
	A D;
	cout<<"在函数function中抛掷出overflow类异常。"<<endl;
	throw overflow();
}
void main()
{
	cout<<"在main函数中"<<endl;
	try
	{
		cout<<"在try块中调用function()。"<<endl;
		function();
	}
	catch(overflow E)
	{
		cout<<"捕获到overflow类型异常,进入catch异常处理程序。"<<endl;
		cout<<E.ShowReason()<<endl;
	}

	cout<<"异常处理完毕,返回main函数。"<<endl;
    cin.get(); //等待结束,以便调测程序,可以删除
}

⌨️ 快捷键说明

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