JS error mechanism: In JS if you encounter errors he will not be immediately thrown he will not find the current execution environment, see whether the current can be stopped, if not stop to go to the higher level of the environment to find (step-by-step search) has been found to handle the error environment. LET fn = () =>{alert (1)}let fn2 = () =>{alert (2)} var promise = new Promise (function (resolve,rejected) {//settimeout ( ) =>{fn ()//resolve () Rejected ("HelloWorld")//At this time reject does not trigger},1000);//timer will cause memory leakage, so to empty the timer})// This is a good decoupling method (to make it separate or less contact)//a Promise represents a separate program Promise.then (function () {return new Promise (function (succeful, Failed) {SetTimeout (() =>{fn2 ()},1000)})},function (e) {console.log (e);}). Then ()//The input chain syntax result is 1 hellowrold//js error mechanism: In JS if you encounter errors he will not immediately throw him will not//he will find the current execution environment, see if the current can be stopped, if not stop to go to the superior environment (search)// Always found in an environment where errors can be handled
JS error mechanism