freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

c面向?qū)ο蟪绦蛟O(shè)計第12章異常處理(參考版)

2025-01-12 00:59本頁面
  

【正文】 } / / ... }。 void init() 。 } / / ... }。 init( ) 。 void init() 。 C++異常處理機制的好處(續(xù)) ? 在異常發(fā)生時,能夠撤銷對象,并自動調(diào)用析構(gòu)函數(shù)進行善后處理, 釋放對象所占用的系統(tǒng)資源。 – 通常情況下,類的創(chuàng)建者監(jiān)控代碼段,從類中拋出異常。 } ... C++異常處理 機制的好處 ? 將程序中正常處理的代碼(描述問題的算法)與異常處理代碼分離開來,提高了程序的可讀性。 \n。 ... try { p = new int[32]。 } return 0。 else cout Quotient is a/b \n。 cin a b。 使用異常類 使用異常類(續(xù)) int main() { int a, b。 } MyException(char *s) { strcpy(str_what, s)。 class MyException { public: char str_what[80]。 例如: ? 實際應(yīng)用中使用的大多數(shù)異常類遠比MyException要復(fù)雜。 ? 在實際程序中,大多數(shù)異常的類型都是類,而不是內(nèi)置數(shù)據(jù)類型(標(biāo)準(zhǔn)類型)。 } catch(...) { // catch all other exceptions捕獲所有其他的異常 cout Caught One!\n。 // throw double } catch(int i) { // catch an int exception cout Caught i 39。a39。 } } 捕獲所有其他的異常 void Xhandler(int test) { try{ if(test==0) throw test。 // throw char if(test==2) throw 。 // throw int if(test==1) throw 39。 } catch(int i){ } return 0。 } int main() { //... try{ set_terminate(myterm)。 void myterm() //自定義的運行終止函數(shù) { coutThis is my terminater.endl。 ? 程序員也可以編寫自己的終止函數(shù),然后通過 set_terminate函數(shù)傳遞給異常處理模塊,使系統(tǒng)在找不到相匹配的異常錯誤處理模塊時調(diào)用該函數(shù)。 自定義運行終止函數(shù) ? 如果在程序中拋出了一個未被處理的異常信息,系統(tǒng)將調(diào)用 C++標(biāo)準(zhǔn)庫中的函數(shù)terminate( )。 ? 如果上一級模塊仍然不能處理,就再傳遞給其上一級,如此逐級上傳,如果到最高一級還無法處理。 } abnormal program termination ? 執(zhí)行上面的程序時,如果輸入的除數(shù)為零,就會發(fā)生程序非正常終止。 return 1。 cout (m/n)endl。 cinmn。 int main( ) { int m,n。 return 0。 Xhandler(3)。 Xhandler(2)。 } } 每個 catch語句所能捕獲的異常必須是不同類型 使用多個 catch語句(續(xù)) int main( ) { cout start\n。 cout str 39。\n39。 else throw Value is zero。 //異常信息從函數(shù)內(nèi)部拋出 return x/y
點擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1