BZ易风

导航

 

 

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

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

结果:

 

posted on 2021-08-25 10:12  BZ易风  阅读(29)  评论(0编辑  收藏  举报