close

#include <iostream>
#include <stdexcept>
using namespace std;

int Ipt(int n)
{
    if(n<0)
    {
        throw invalid_argument{
        "XD" /*遇到例外狀況要傳出的訊息*/
        };
    }else
    return 100;
}

int main()
{
    int n,Opt;
    while(cin>>n)
    {
        Opt=0;
        try{
        Opt = Ipt(n);
        }catch(invalid_argument &e){
        cout<<"Exception: "<<e.what()<<endl; /*catch e物件,使用member function回傳exception的訊息*/
        }
        cout<<"Opt= "<<Opt<<endl;
    }
    return 0;
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Kuihao 的頭像
    Kuihao

    溫暖午後的金針田__孕育有趣的創新

    Kuihao 發表在 痞客邦 留言(0) 人氣()