C++抛出异常exception

来源:互联网 发布:淘宝男装店铺名字 编辑:程序博客网 时间:2024/06/03 18:14

// testMyException.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    try
    {
        //cout<<"1、send int exception"<<endl;
        //throw(10);

        cout<<"2、send char exception"<<endl;
        //throw('d');


        //cout<<"3、send other exception"<<endl;
        //throw(2.3);

        // 4、也可以定义一个类,将类对象(或类地址,或类指针抛出去)
    }
    catch(int a)
    {
        cout<<"1、catch int value is "<<a<<endl;
    }
    catch(char a)
    {
        cout<<"2、catch char value is "<<a<<endl;
    }
    catch(...)
    {
        cout<<"3、catch ...  "<<endl;
    }

    system("pause");
 return 0;
}

0 0
原创粉丝点击