//error_handing
/*try{
if(有異常情況)
throw 數(shù)據(jù);
}監(jiān)視數(shù)據(jù)是否被拋出
catch (類型倔矾,變量名){}
catch (類型,變量名){}
catch (類型嘴拢,變量名){}
*/
include <iostream>
include <fstream>
using namespace std;
int main(int argc, char const argv[])
{
try {
ifstream fin(argv[1]);
/if(!fin)
throw 100;
*/ char buf[1000];
fin.read(buf,1000);
if (!fin)//異常一旦拋出,不會(huì)再回來執(zhí)行這個(gè)語句了,因此不必須兩個(gè)拋出
throw 100.0;
cout.write(buf,1000);
fin.close();
}
catch(double e){
cout << "double:" << e << endl;
}
catch(long e){
cout << "long :" << e <<endl; //拋出的異常在上面兩個(gè)catch中,都沒有接到奶卓。如果一直沒有接收到相應(yīng)類型,則不會(huì)輸出下面語句
}
/catch(int e){
cout << "int :" << e <<endl; //此時(shí)撼玄,接收到catch語句夺姑。。程序繼續(xù)向下執(zhí)行
}/
catch(...){//如果掌猛,還沒捕獲異常盏浙。此句用于接受所有異常
//可接受所有異常。后面的catch將沒有作用。废膘。后面再加catch竹海,系統(tǒng)也會(huì)報(bào)錯(cuò)
}
cout << "if you want to,try to it !" <<endl;
return 0;
}