码迷,mamicode.com
首页 > 其他好文 > 详细

自定义异常类_1

时间:2018-01-13 20:42:12      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:clu   this   color   and   under   col   const   ...   ons   

1、

// https://www.cnblogs.com/crazyacking/p/4951638.html

#include <iostream.h>
#include <windows.h>

class ExceptionClass1
{
    char* name;
    public:
    ExceptionClass1(const char* name="default name")
    {
        cout<<"Construct "<<name<<endl;
        this->name = (char*)name;
    }
    ~ExceptionClass1()
    {
        cout<<"Destruct "<<name<<endl;
    }
    static void mythrow()
    {
        throw ExceptionClass1("my throw");
    }
};

//*
void main()
{
    //ExceptionClass e("Test");
    try
    {
        ExceptionClass1::mythrow();
        //e.mythrow();
    }
    catch(...)
    {
        cout<<"*********"<<endl;
    }
}
//*/
/*
void main()
{
    ExceptionClass e("Test");
    __try
    {
        e.mythrow();
    }
    __except (EXCEPTION_EXECUTE_HANDLER)
    {
        cout<<"*********"<<endl;
    }
}
//*/

 

2、

3、

4、

5、

 

自定义异常类_1

标签:clu   this   color   and   under   col   const   ...   ons   

原文地址:https://www.cnblogs.com/cppskill/p/8280184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!