Re: 例外處理問題之二

看板Programming作者 (發起錢像亂噴水)時間18年前 (2007/09/13 04:02), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/7 (看更多)
※ 引述《jiannrong.bbs@bbs.wretch.cc (大改名片檔)》之銘言: void print_value() : { try : {if (denominator==0) : { throw 0; } : else if (denominator<0) : { throw " ~~分母<0 這樣是不行的 "; } : else : { : cout << numerator << "/" << denominator << "="; : cout << double (numerator)/double(denominator) << endl; : } } : catch(int err) : { cout <<"有問題"<<endl; } : catch(const …) : { cout <<"其他錯誤"<<endl; } } 最後那個catch的 "..." 不曉得你把它改成什麼, 不過按try的內容來說,最後catch改成 catch(const char* ex) { cout << "其他" << endl; } 即可. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.231.68.224
文章代碼(AID): #16w4MyMB (Programming)
文章代碼(AID): #16w4MyMB (Programming)