编程语言
首页 > 编程语言> > C++(自定以异常类)

C++(自定以异常类)

作者:互联网

C++(自定以异常类)

class myException //自定以异常类
{
public:
	void printError()
	{
		cout << "自定以异常类" << endl;
	}
};
int myDevide(int a, int b)
{
	if (b == 0)
	{
		throw myException(); //匿名对象
	}
	return 0;
}
int main()
{
	try
	{
		myDevide(10, 0);
	}
	catch (myException e)
	{
		e.printError();
	}
	return 0;
}

标签:cout,自定,printError,myException,C++,异常
来源: https://www.cnblogs.com/lodger47/p/14705278.html