国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

實例解析js中try、catch、finally的執行規則

2024-05-06 16:35:24
字體:
來源:轉載
供稿:網友

try:  語句測試代碼塊的錯誤,一般把可能會出錯的代碼放到這里

catch: 只有try里面的代碼塊發生錯誤時,才會執行這里的代碼,參數err記錄著try里面代碼的錯誤信息

finally: 無論有無異常里面代碼都會執行

try{ console.log(0); }catch (err){ console.log(1); console.log(hello); }finally { console.log(2); } //最后結果分別打印出 0 2 /* try{ a.b.c(); }catch (e){ console.log(1); console.log(hello); }finally { console.log(2); } */ //最后結果分別打印出 1 2 報錯:hello is not defined /* try{ a.b.c(); }catch (e){ console.log(1); try{  console.log(hello); }catch (e){  console.log(3); } }finally { console.log(2); console.log(word); }  */ //最后結果分別打印出 1 3 2 報錯:word is not defined /* try{ a.b.c(); }catch (e){ console.log(1); console.log(hello); }finally { console.log(2); console.log(word); }*/ //最后結果分別打印出 1 2 報錯:word is not defined

總結:

try里面的代碼報錯的時候,catch里面的代碼才會執行,finally里面的代碼永遠會執行

catch和finally里面,正常的代碼會從上到下順序執行

如果只是catch里面代碼出錯,則報catch里面的錯誤

如果catch和finally都出錯則會報finally里面的錯誤

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持VeVb武林網!


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江山市| 奇台县| 察隅县| 临泽县| 邯郸市| 福贡县| 木里| 久治县| 哈巴河县| 德惠市| 盘锦市| 永和县| 宁河县| 嘉黎县| 乳源| 漳浦县| 桐梓县| 滨海县| 南京市| 吴堡县| 白城市| 海阳市| 玉田县| 收藏| 新源县| 怀化市| 栾川县| 兴国县| 五寨县| 灌南县| 沧州市| 梧州市| 富川| 大丰市| 惠安县| 望城县| 湘西| 和田县| 临武县| 南陵县| 安庆市|