📄 d_12_2.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 + -