美文网首页
Error will not catch in try catc

Error will not catch in try catc

作者: 超薄智能 | 来源:发表于2019-05-25 11:44 被阅读0次

    Sometime cannot use await function in a callback, use promise chain will be ok

    var process1 = ()=>{
        try{
            promise;
        }catch(error){
            console.log(error);
        }
    }
    
    var process2 = ()=>{
        promise.then().catch(error=>console.log(error));
    }
    
    var promise = new Promise((r,j)=>{
        setTimeout(()=>{
            j('rejected');
        },300)
    })
    
    
    process1();
    process2();
    

    相关文章

      网友评论

          本文标题:Error will not catch in try catc

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