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;
    }

  • 相关阅读:
    pointnet++之classification/train.py
    pointnet++的pytorch实现
    xavier初始化的简单推导
    z+f数据解析
    ubuntu安装dia
    卷积,reLu,池化的意义
    Split
    .net程序调试一:快速定位异常
    Memcached (第一篇)
    System.Web.Caching.Cache类 缓存 各种缓存依赖
  • 原文地址:https://www.cnblogs.com/w413133157/p/1666779.html
Copyright © 2011-2022 走看看