Promise3

作者: 郭的妻 | 来源:发表于2018-06-21 20:33 被阅读3次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <script>
        // 结论
        // 1 .错误不会被重复铺获;
        // 2 .catch返回一个promise实例,并且 是resolve的状态
        // 3 .抛出错误变为reject状态,所以绕过了两个then直接
        // 跑到最下面catch
        console.log("here we go...");
        new Promise(resolve => {
            setTimeout(()=>{
                resolve();
            },2000)
        })
            .then(()=>{
                console.log("start");
                throw new Error ("test error")
            })
            .catch(err=>{
                console.log("I catch:",err)
                throw new Error("another error")
            })
            .then(()=>{
                console.log("arrive here!");
            })
            .then(()=>{
                console.log("here...")
            })
            .catch(err =>{
                console.log("No ,I Catch:",err)
            })
    </script>
    </body>
    </html>

    相关文章

      网友评论

        本文标题:Promise3

        本文链接:https://www.haomeiwen.com/subject/mygcyftx.html