亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

實(shí)例解析js中try、catch、finally的執(zhí)行規(guī)則

 更新時(shí)間:2017年02月24日 14:42:23   作者:lc5910  
本文主要通過實(shí)例解析來更好的了解js中try、catch、finally的執(zhí)行規(guī)則,具有很好的參考價(jià)值,下面跟著小編一起來看下吧

try:  語句測(cè)試代碼塊的錯(cuò)誤,一般把可能會(huì)出錯(cuò)的代碼放到這里

catch: 只有try里面的代碼塊發(fā)生錯(cuò)誤時(shí),才會(huì)執(zhí)行這里的代碼,參數(shù)err記錄著try里面代碼的錯(cuò)誤信息

finally: 無論有無異常里面代碼都會(huì)執(zhí)行

try{
 console.log(0);
 }catch (err){
 console.log(1);
 console.log(hello);
 }finally {
 console.log(2);
 }
 //最后結(jié)果分別打印出 0 2
 /*
 try{
 a.b.c();
 }catch (e){
 console.log(1);
 console.log(hello);
 }finally {
 console.log(2);
 }
 */
 //最后結(jié)果分別打印出 1 2 報(bào)錯(cuò):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);
 } 
 */
 //最后結(jié)果分別打印出 1 3 2 報(bào)錯(cuò):word is not defined
 /*
 try{
 a.b.c();
 }catch (e){
 console.log(1);
 console.log(hello);
 }finally {
 console.log(2);
 console.log(word);
 }*/
 //最后結(jié)果分別打印出 1 2 報(bào)錯(cuò):word is not defined

總結(jié):

try里面的代碼報(bào)錯(cuò)的時(shí)候,catch里面的代碼才會(huì)執(zhí)行,finally里面的代碼永遠(yuǎn)會(huì)執(zhí)行

catch和finally里面,正常的代碼會(huì)從上到下順序執(zhí)行

如果只是catch里面代碼出錯(cuò),則報(bào)catch里面的錯(cuò)誤

如果catch和finally都出錯(cuò)則會(huì)報(bào)finally里面的錯(cuò)誤

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論