zoukankan      html  css  js  c++  java
  • 异常(3)


    #include "stdafx.h"
    #include <iostream.h>
    #include <string.h>

    //
    类描述异常信息
    class  Matherr
    {
    protected:
        char m_szMsg[32];
    public:
        virtual const char *GetMsg()const
        {
            return m_szMsg;
        }
    };

    class  Overflow:public Matherr
    {
    public:
        Overflow()
        {
            strcpy(m_szMsg, "Overflow");
        }
        const char *GetMsg()const
        {
            cout << "Overflow::GetMsg()" << endl;
            return m_szMsg;
        }
    };

    class  Underflow:public Matherr
    {
    public:
        Underflow()
        {
            strcpy(m_szMsg, "Underflow");
        }
        const char *GetMsg()const
        {
            cout << "Underflow::GetMsg()" << endl;
            return m_szMsg;
        }
    };

    class  Zerodivide:public Matherr
    {
    public:
        Zerodivide()
        {
            strcpy(m_szMsg,"Zerodivide");
        }
        const char *GetMsg() const
        {
            cout << "Zerodivide::GetMsg()" << endl;
            return m_szMsg;
        }
    };

    int main(int argc, char* argv[])
    {   
        try
        {
            //
    下面两个子类的异常都会初下面的基类接收
            throw Zerodivide();
            throw Overflow();
        }
        //
    基类来接收异常
        catch (Matherr &theMat)
        {
            cout << theMat.GetMsg() << endl;
        }
        return 0;
    }

  • 相关阅读:
    仿函数(functor)
    七周七语言
    面向签名编程
    git checkout简介
    .gitkeep常用写法
    PhpStorm terminal无法输入命令的解决方法
    原 在windows上创建文件名以“.”开头的文件
    cmd 里面运行git提示“不是内部或外部命令,也不是可运行的程序”的解决办法
    .gitkeep
    git/github运用
  • 原文地址:https://www.cnblogs.com/w413133157/p/1666779.html
Copyright © 2011-2022 走看看