You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionf(){try{console.log(0);throw'bogus';}catch(e){console.log(1);returntrue;// this return statement is suspended// until finally block has completedconsole.log(2);// not reachable}finally{console.log(3);returnfalse;// overwrites the previous "return"console.log(4);// not reachable}// "return false" is executed now console.log(5);// not reachable}f();// console 0, 1, 3; returns false
文档: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#The_finally_block
总结就是:『
finally
中的代码』总会执行,无视try/catch
里面的任何throw error
&return
,『finally
中的代码』执行时机是先于任何『next/outer的语句』。The text was updated successfully, but these errors were encountered: